Files
speckle-unity/Assets/First person controller/Scripts/Components/Jump.cs
T
2021-04-14 14:38:05 +01:00

33 lines
679 B
C#

using UnityEngine;
public class Jump : MonoBehaviour
{
[SerializeField]
GroundCheck groundCheck;
Rigidbody rigidbody;
public float jumpStrength = 2;
public event System.Action Jumped;
void Reset()
{
groundCheck = GetComponentInChildren<GroundCheck>();
if (!groundCheck)
groundCheck = GroundCheck.Create(transform);
}
void Awake()
{
rigidbody = GetComponent<Rigidbody>();
}
void LateUpdate()
{
if (Input.GetButtonDown("Jump") && groundCheck.isGrounded)
{
rigidbody.AddForce(Vector3.up * 100 * jumpStrength);
Jumped?.Invoke();
}
}
}