36 lines
786 B
C#
36 lines
786 B
C#
|
using UnityEngine;
|
||
|
|
||
|
public class FallingDetection : MonoBehaviour
|
||
|
{
|
||
|
public GameObject _LevelManager1;
|
||
|
private CharController script1;
|
||
|
bool grounded;
|
||
|
private Rigidbody2D playerRigidbody;
|
||
|
public bool isFalling;
|
||
|
private Animator animator;
|
||
|
public int counter = 0;
|
||
|
|
||
|
private void Start()
|
||
|
{
|
||
|
animator = GetComponent<Animator>();
|
||
|
playerRigidbody = GetComponent<Rigidbody2D>();
|
||
|
}
|
||
|
|
||
|
private void Update()
|
||
|
{
|
||
|
script1 = _LevelManager1.GetComponent<CharController>();
|
||
|
grounded= script1.grounded;
|
||
|
Vector3 velocity = playerRigidbody.velocity;
|
||
|
if (!grounded && velocity.y < -0.1f){
|
||
|
if(counter++>90||isFalling){
|
||
|
isFalling = true;
|
||
|
animator.SetBool("IsFalling", true);
|
||
|
counter = 0;}
|
||
|
} else {
|
||
|
isFalling = false;
|
||
|
counter = 0;
|
||
|
animator.SetBool("IsFalling", false);}
|
||
|
}
|
||
|
|
||
|
}
|