Question by
akaoctopus · Mar 25 at 05:22 PM ·
colliderscollision detection
Collider not updating public variable
So I created an empty object (GroundCollider) as a child of my Character and set it with a box collider and the following script.
public class GroundCheck : MonoBehaviour
{
public bool isGrounded;
public LayerMask groundMask;
private void OnTriggerEnter(Collider collider)
{
isGrounded = collider != null && (((1 << collider.gameObject.layer) & groundMask) != 0);
}
private void OnTriggerExit(Collider collider)
{
isGrounded = false;
}
}
I then get that value from my main movement script as
transform.Find("GroundCollider").GetComponent<GroundCheck>().isGrounded;
but seems to never change. Is this a legit workflow? I'm a beginner so I'm not sure if I should investigate an error in my code and parameters or if it just doesn't work because of given restrictions of Unity and public variables handling.
Comment
Your answer
