- Home /
Why when my Grounded equals false my if statement not play?
Collider2D[] colliders = Physics2D.OverlapCircleAll(m_GroundCheck.position, k_GroundedRadius, m_WhatIsGround);
for (int i = 0; i < colliders.Length; i++)
{
if (colliders[i].gameObject != gameObject)
{
Debug.Log("Touching");
animator.SetTrigger("Grounded");
m_Grounded = true;
if (!wasGrounded)
OnLandEvent.Invoke();
}
else
{
m_Grounded = false;
animator.ResetTrigger("Grounded");
}
}
Debug.Log(m_Grounded);
if (m_Grounded = false)
{
Debug.Log("NotGrounded");
animator.SetTrigger("Jump");
animator.ResetTrigger("Grounded");
}
Comment
Best Answer
Answer by metalted · Mar 17, 2020 at 07:55 PM
Your if statement on line 20 says: if(m_grounded = false). This is an assignment, and i'm pretty sure this doesn't even compile. Anyway, you are experiencing the problem... So the check the value of m_Grounded you use the == , instead of a single =. So like this : if(m_Grounded == false){...}. There is also a shorter way of writing this which uses the exclamation mark: if(!m_Grounded){...}