Animation on Collision
Hey, I am trying to make a script that once the player steps on the object ( a button) an animation plays. Unfortunately, this isn't going too well for me. I've attached the code as a picture for reference, but when the player collides with the button I get the error:
MissingComponentException: There is no 'Animation' attached to the "button (1)" game object, but a script is trying to access it. You probably need to add an Animation to the game object "button (1)". Or your script needs to check if the component is attached before using it.
I'm sure I have attached the animation but nothing seems to work, I'm assuming its something to do with the 'Or your script needs to check if the component is attached' but I'm not too sure how to go about that. any help will be greatly appreciated.
Answer by DougRichardson · Nov 08, 2017 at 07:41 PM
You don't have an Animation component, you have an Animator. Changing your GetComponent call in Start will resolve the MissingComponentException.
To work with Animator, you want to work with its state machine instead of trying to blend animations explicitly like you are doing. Check out this answer here for more info.
Your answer
Follow this Question
Related Questions
How to modify coliders during animation 0 Answers
Help with OnTriggerEnter Not working correctly? 1 Answer
Rotate a hinge joint on its own 0 Answers
How to make a system in unity 0 Answers