- Home /
How to let other object know i have enter a collider of a different object
Hi, I have 2 different object : object A and object B;
object A have animation but object B do not..
So, how to make object A to play its animation after detecting that i have enter the collider of object B..? ( Yes, i know there is a way to detect the boolean of object B true or false and by that playing object A animation, but since object B do not have any animation, i not sure how to do it...)
p/s: I have used box collider of object A to play other set of animation in object A.. My object A have different set of animation with it..
Thanks for reading.. and help
Answer by andyisbonza · Feb 02, 2016 at 10:29 AM
The question isn't really clear. Are you detecting the collision on object A or object B? Are you just saying that object A has the collider code, and its animation should ONLY play if it collides with Object B? Or are you saying that object B is detecting the collision and you want it to play Object A's animation?
In the first case, you'd say something like:
function OnTriggerEnter (other : Collider)
{
if other.gameObject.name == "Object B"
{
GetComponent.<Animation>().Play('animation_name');
}
}
In the second case, you'd write something like:
function OnTriggerEnter (other : Collider)
{
other.gameObject.GetComponent.<Animation>().Play('animation');
}