- Home /
Play animation when colliding with trigger!
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.
Check the collider isTrigger and then implement your code in OnTriggerEnter
Answer by TheRichardGamer · Oct 26, 2013 at 10:02 AM
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 :)
Answer by Stratosphere_Studios · Mar 08, 2014 at 07:36 PM
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");
}
}
Answer by L20GAMES · Oct 28, 2013 at 05:31 AM
Thanks, I realised i was missing out the OnTriggerEnter, Thanks for everyone's help.
Your answer
Follow this Question
Related Questions
I dont get the new animation window 0 Answers
Scale animation doubt 0 Answers
Making an animation play when you press down 2 keys 1 Answer
A node in a childnode? 1 Answer