-
Notifications
You must be signed in to change notification settings - Fork 0
/
PlayerController.cs
123 lines (102 loc) · 3.24 KB
/
PlayerController.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class PlayerController : MonoBehaviour
{
public GameObject rockPrefab;
private Rigidbody rockRb;
private Rigidbody playerRb;
public Animator playerAnim;
private GameManager gameManager;
private ThrustForward thrustScript;
public float throwForceUp = 0;
public GameObject arrowPointer;
private float verticalInput;
[SerializeField] float rotateSpeed;
// private float arrowMaxValueX = 90;
// private float arrowMinValueX = 0;
// float arrowY;
// float arrowZ;
// private Vector3 arrowCurrentEulerAngles;
// Start is called before the first frame update
void Start()
{
playerAnim = GetComponent<Animator>();
playerRb = GetComponent<Rigidbody>();
gameManager = GameObject.Find("Game Manager").GetComponent<GameManager>();
thrustScript = rockPrefab.GetComponent<ThrustForward>();
}
// Update is called once per frame
void Update()
{
playerAnim.SetFloat("Speed_f", 0.0f);
AdjustThrowAngle();
if (gameManager.isGameActive == true)
{
ThrowStone();
}
if (gameManager.currentSceneIndex == 11)
{
playerAnim.SetTrigger("DanceParty");
}
/*
if (arrowPointer.transform.rotation.x > arrowPointerMaxPos)
{
transform.rotation.x = arrowPointerMaxPos;
}
arrowPointerMaxPos)
{
arrowPointer.transform.rotation = arrowPointer.transform.Rotate
(arrowPointerMaxPos, 2.54f, .4f, Space.Self);
}
*/
// while (gameManager.isGameActive)
// {
// }
}
public void ThrowStone()
{
if (Input.GetKey(KeyCode.Space))
{
OnSpaceBarHold();
}
if (Input.GetKeyUp(KeyCode.Space))
{
playerAnim.SetTrigger("Throw");
StartCoroutine(ThrowCoroutine());
}
}
public void DanceParty()
{
playerAnim.SetTrigger("DanceParty");
}
void AdjustThrowAngle()
{
verticalInput = Input.GetAxis("Vertical");
arrowPointer.transform.Rotate(Vector3.right * Time.deltaTime * rotateSpeed * -verticalInput);
}
/*
if (arrowPointer.transform.eulerAngles.x < -90.0f)
{
arrowPointer.transform.eulerAngles = new Quaternion(-90f, 0.0f, 0.0f, );
}
*/
float OnSpaceBarHold()
{ if (throwForceUp < 50)
{
throwForceUp += 15 * Time.deltaTime;
Debug.Log("throwForceUp is now: " + throwForceUp);
}
return throwForceUp;
}
IEnumerator ThrowCoroutine()
{
yield return new WaitForSeconds(1);
thrustScript.throwForce = throwForceUp;
rockPrefab.transform.rotation = arrowPointer.transform.rotation;
Instantiate(rockPrefab);
gameManager.UpdateRockCount(1);
throwForceUp = 0;
}
}