-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlayerController.cs
132 lines (83 loc) · 2.89 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
124
125
126
127
128
129
130
131
132
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour
{
[SerializeField] private float speed = 0.6f;
private Rigidbody2D rb;
//two methods of jump i have the arrow key and the space bar method ivan on tech is the arropw key method and the one in use
private float jumpInput;
[SerializeField]
private float jumpForce;
private float jumpsDone;
private float prevJumpInu;
private TextManger textManger;
//[SerializeField]
private float moveInput;
[SerializeField]
private float jumpsAllowed;
private bool isJumping;
// Start is called before the first frame update
void Start()
{
rb = GetComponent<Rigidbody2D>();
isJumping = false;
jumpsDone = 0;
jumpsAllowed = 3;
prevJumpInu = 0;
}
// Update is called once per frame
private void FixedUpdate() //fixed update is called at each physcis step can be called 0 times or multiple time - its called all the time its essentially what give this game motion
{
//-1 left, 0 is still, 1 is right
moveInput = Input.GetAxis("Horizontal");
//easy way to get movment in there
rb.velocity = new Vector2(moveInput * speed, rb.velocity.y);
jumpInput = Input.GetAxis("Vertical");
if (jumpInput > 0 && jumpsAllowed > jumpsDone && prevJumpInu == 0)
{
rb.velocity = new Vector2(rb.velocity.x, jumpForce);
Debug.Log("jump");
isJumping = true;
jumpsDone ++;
//else
//{
//isJumping = false;
//}
}
prevJumpInu = jumpInput; //we set the previous input to the current input now when run this method we will have updated the prev input to a current position there in
//if (Input.GetButtonDown("Jump"))
//{
// Jump();
//}
}
private void OnCollisionEnter2D(Collision2D collision)
{
if(collision.gameObject.CompareTag("Ground"))
{
isJumping = false;
jumpsDone = 0;
}
else if (collision.gameObject.CompareTag("Coin"))
{
Destroy(collision.gameObject);
TextManger.textManager.IncreaseScore();
}
Debug.Log(collision.gameObject.tag);
}
//private void Jump()
//{
//rb.AddForce(Vector3.up * jumpForce);
//}
private void SpeedSetter()
{
//moveInput = moveInput * speed;
}
void Update()//uiipdate is called blindley at 60 seconds per frame
{
//if (Input.GetButtonDown("Jump"))
//{
//Jump();
//}
}
}