- Home /
The question is answered, right answer was accepted
How to make a lot of simple interaction that triggers a lot of animations?
Hello everyone!
I got a question.
I want to make a game where you walk in a building and you can interact with a lot of objects. Lets say I have a room with a few objects like a trashcan, door, few bookcases etc. I want to make them play an animation when I have my mouse on them (hover maye?) and then press E button on my keyboard, and when i do, then the object that I have my mouse on plays an animation, and stays on the end (like open a chest, and the chest stays open, and to close I have to press E again on the chest.) (something like an RPG game) I am making an RPG game by the way, if that is needed to know to help solve this problem.
How can I script it the best way? And how do I assemble the animator the best?
Thank you all in advance,
Daniel Nowak Janssen.
Answer by LMan · Jan 04, 2016 at 02:32 PM
One way you could do it:
Each object needs an animator controller of it's own that will function as it's state machine. the animator controller will contain boolean variables that will control which animation gets played when the object is interacted with.
Thank you!
I got it working somehow. Do I need to make for each animation another state machine and animator controller? or can I put the same animator controller on each object that I want to animate? Because now I made an animator and animation on a dresser, and when I press the opening button the dresser opens, and I can pick a piece of cloth out of it with the interaction button. And when I press the opening button on the dresser it closes.
But I was wondering if I can use the same animator controller on more objects, with each another animation... It won's cause a lot of errors right?
If you want different animations you're going to need to make separate Animator Controllers I'm afraid. I would recommend making copies of your animator controller file in the project folder and then changing the motion fields of the states in the copies to point towards the animations you want.
That way you keep the state machine the way it is and don't have to set up the bools or change any scripts.
I got a quick question, How can I freeze the camera on interaction? So I press E and I start an interaction, and I want the camera to freeze on that position. So like this : Press E, open door & camera rotation and position freeze, animation en & camera rotation and position unfreeze.
How can I achieve that?
Thank you again for your help and have a nice day @L$$anonymous$$an,
$$anonymous$$ Nowak Janssen.
Follow this Question
Related Questions
Transform Of GameObject getting changed incorrectly after updating RuntimeAnimatorController 0 Answers
How do I keep scroll rect working with custom pointer events? 1 Answer
How to detect if UI button is clicked? 3 Answers
Mecanim Animation events fires multiple times 1 Answer
Animation Plays well,but teleportation effect happens briefly when parenting the object to other obj 0 Answers