- Home /
Animation trigger?
I have a shutter like door which I have animated in 3ds max, i have imported this into unity and split the animation so i have an idle state starting from frame 1 ending on frame 2. I also have a open animation starting frame 2 to 100.
I have a cube box that i want to be the trigger for playing the animation, ie once the first person camera hits the box with the mouse the animation will play.
Please can anyone help me on how I should go about doing this?
Thanks
Answer by skovacs1 · Nov 03, 2010 at 05:03 PM
The first person camera hits the box with the mouse?
While the thought of the camera GameObject or some script with the ability to reach out into the world to grab the mouse and then use it to physically assault a box sounds like good times, I'll answer this question assuming that you meant something like "How do I trigger an animation when the mouse clicks on a box?"
clickAnimation.js (Attached to the box)
var door : GameObject; //Assign this in the editor or in Start, find the door
function OnMouseUp() { door.animation.Play("Open"); }
O$$anonymous$$ay if this is the case how do you assign the door to the editor?
thanks
Select the object with the script attached and drag the door onto the door slot in the attached script in the inspector.
okay but there is no door slot, just the name of the script once it's on the object.
do you need a var = door ? ..
lol so sorry about this must be anoying , im new to unity . but the error console still displays expecting ; .. is this script correct .. and still having the problem dragging the door to the script.
Fixed. Sorry about that. You should have mentioned the error. I'm flipping between c# and javascript so often that I sometimes screw up the syntax. Once the script compiles (without errors) it will have the door slot. Attach it to the box. Drag the door that has an animation named "Open" onto the door slot of the box's instance of the script.
Answer by corriedotdev · Mar 18, 2013 at 10:35 PM
var Animator : GameObject; //Assign this in the editor character with animation
function OnTriggerEnter(){
Animator.animation.Play("Open"); // name the animation to be played
}
Attach script to empty cube. This method is if you dont want to add a mouse click :)