public static bool Grounded = true;
public GameObject Bird1;
public GameObject Bird2;
// Start is called before the first frame update
void Start()
{
Bird1.SetActive(false);
Bird2.SetActive(false);
}
// Update is called once per frame
void Update()
{
if(Grounded == true)
{
Bird1.SetActive(false);
}
if(Grounded == true);
{
Bird2.SetActive(true);
}
if(Grounded == false)
{
Bird1.SetActive(true);
}
if(Grounded == false);
{
Bird2.SetActive(false);
}
CheckIfGrounded();
}
private void OnCollisionEnter(Collision col)
{
CheckIfGrounded();
}
private void CheckIfGrounded()
{
RaycastHit[ ] hits;
//We raycast down 1 pixel from this position to check for a collider
Vector3 positionToCheck = transform.position;
hits = Physics.RaycastAll (positionToCheck, new Vector3 (0, -1), 0.01f);
//if a collider was hit, we are grounded
if (hits.Length > 0) {
Grounded = true;
}
}
private void OnCollisionExit(Collision col)
{
Grounded = false;
}