-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplayer.cs
69 lines (57 loc) · 1.75 KB
/
player.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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Player : MonoBehaviour
{
[SerializeField] private Transform GroundCheckTransform = null;
[SerializeField] private LayerMask playermask;
private bool JumpKeyWasPressed;
private float HorizontalImput;
private Rigidbody RigidBodyComponent;
private int SuperJumpsRemaining;
private float SprintKeyWasPressed;
// Start is called before the first frame update
void Start()
{
RigidBodyComponent = GetComponent<Rigidbody>();
}
// Update is called once per frame
void Update()
{
// check if space key is pressed down for jump
if (Input.GetKeyDown(KeyCode.Space) == true)
{
JumpKeyWasPressed = true;
}
HorizontalImput = Input.GetAxis("Horizontal");
}
// fixed update is called once every pychics update
private void FixedUpdate()
{
RigidBodyComponent.velocity = new Vector3(HorizontalImput, RigidBodyComponent.velocity.y, 0);
if (Physics.OverlapSphere(GroundCheckTransform.position, 0.1f, playermask).Length == 0)
{
return;
}
if (JumpKeyWasPressed == true)
{
float JumpPower = 5f;
if (SuperJumpsRemaining > 0)
{
JumpPower *= 2;
SuperJumpsRemaining--;
}
RigidBodyComponent.AddForce(Vector3.up * JumpPower, ForceMode.VelocityChange);
JumpKeyWasPressed = false;
//made u double jump
}
}
private void OnTriggerEnter(Collider other)
{
if (other.gameObject.layer == 7)
{
Destroy(other.gameObject);
SuperJumpsRemaining += 1;
}
}
}