I am trying to figure out whether the animator parameter has been set to true when the player collides with an object. I have the following code on a script with the player. However, this is checking the animator for the player. How can I check the collided objects’s parameters?
From the collision variable you can get the Collider, and from that you can use GetComponent() to retrieve the animator on that GameObject.
BEWARE that it may not be present on that GameObject in all cases, so it is up to you to guard the usage of anything you get back from GetComponent() to ensure it is not null.
Just for my own clarification, checking for the presence could be done like this?
if(collision.GetComponent<Animator>()) {
// exists, now check the bool
}
else {
// maybe do something else if no Animator component, maybe do nothing
}
var animator = GetComponent<Animator>();
if (animator)
{
// go to town with your properties
}
EDIT: for the C# enthusiasts out there, AFAIK you may NOT use the null coalescing operator in lieu of the above if statement because Component derives from UnityEngine.Object and hence has that bool override.