- Home /
Collider Animation
How would i make it so that when i hit a collider, and when im in that certain collider i press the button 'h' The animation starts to go, I did try and write this code myself but it didnt work, This is my code
function OnCollitionEnter ()
{
if(Input.GetKey("h"))
animation.Play("Test Animation");
} If anybody could help or point in the right direction that would be great ? Thanks
You have a small typo in OnCollitionEnter..don't know if it's the same in your code but it should be OnCollisionEnter(). The OnCollisionEnter function will only be triggered that one frame where the collision is first detected i think. $$anonymous$$aybe try setting a variable to true or false using the functions OnCollisionEnter() and OnCollisionExit().
Sorry try using the OnCollisionStay() function ins$$anonymous$$d, should check every frame :)
Answer by benjimazza · Feb 23, 2012 at 01:37 PM
Fixed i figured it out :D
Can you post the final script please?, I have also been faced with this problem before.
It is alot like What i wrote i just typed some things wrong,
// Attach this script to your object and set IsTrigger under the
//box collider :)
function OnTriggerEnter(hit : Collider)
{
animation.Play("NA$$anonymous$$E OF ANI$$anonymous$$ATION");
}
Your answer
Follow this Question
Related Questions
How to jump on to a turret gun 2 Answers
Animation Help!!!!! 1 Answer
Animation stoping!! 1 Answer
Sniper Zoom!!! 1 Answer