I’m trying to get a statue to fall over when you come in collision with a box collider. The statue is called “faller” and the animation I want to play is “monstersfall”, I want it to play when the “Player” collides with the box collider, also the box collider is called “GameObject”. I’ve tried many times but nothing’s working. Please help.
This is what you should do: On the box collider for your “Game Object” check “Is Trigger” and then make a script with the following code:
var FallerObject : GameObject; //Implement your Faller game object into this variable in the inspector
function OnTriggerEnter (Other : Collider){
if(Other.gameObject.tag == "Player"){
FallerObject.animation.Play("monstersfall");
}
}
Just be sure to tag your player to “Player” and you’ll be fine
Thanks, I realised i was missing out the OnTriggerEnter,
Thanks for everyone’s help.
i just edited that script a little bit, just so you can swap the animation instead of going into the script and editing it. Credit for the original script, of course, goes to TheRichardGamer.
var yourAnimation : Animation; // choose the animation which will start when triggered
var FallerObject : GameObject; //Implement your Faller game object into this variable in the inspector
function OnTriggerEnter (Other : Collider){
if(Other.gameObject.tag == "Player"){
FallerObject.animation.Play("yourAnimation");
}
}