- Home /
Reset Animation on Death of Player
I have a part of my level where the player travels across a platform, avoiding obstacles and moving objects in order to reach the end. Should the player say get knocked off and fall to his death, I would want the platform that he was riding to reset to its original position and wait till the player jumps back on for another attempt.
Here is a picture demonstrating what I want to have!
Here is the code I have so far. I have it to where it waits 3 seconds after the player jumps on to start, but I dont know how to get it to reset the animation and wait 3 seconds after the player jumps on!
var anim : String;
var animatingObject : GameObject;
function OnTriggerEnter(other : Collider)
{
if (other.tag == "Player")
{
yield WaitForSeconds(3.0);
animatingObject.animation.Play();
}
}
Any help or guidance would be very greatly appreciated!
Let me know if you need any additional info needed to help!
Answer by Maulik2208 · Nov 30, 2012 at 06:23 AM
First of all at the start take the cube position in temporary variables and, when needed reset the position of cube, by using cube.transform.position = new vector3(xtemp,ytemp,ztemp);....and then use Animation.Rewind.....it will rewind the animation, for syntex and other stuff kindly go to help----->scriptreference------>to animation.rewind....... if you found this useful then please mark as right answer so others can Find the working solution easily.....Enjoy.....Hope it will work best for You....
Sorry for the bad english but i think you can understand what i was saying....
Sorry for the link it was a mistake in hurry.....So,please Go to help in unity From there Go To scriptreferences and search animation.rewind and you will get your stuff.....
Alright well I messed around with it, but keep getting error "$$anonymous$$issing$$anonymous$$ethodException: $$anonymous$$ethod not found: 'UnityEngine.Animation.rewind'. Boo.Lang.Runtime.DynamicDispatching.$$anonymous$$ethodDispatcherFactory.ProduceExtensionDispatcher ()"
Here is the script I have so far
var wooden_Pillar_23 : GameObject; var woodenPillar23_anim : Animation; function Rewind (woodenPillar23_anim : animation) : void { } function OnTriggerEnter(other:Collider) { if (other.tag == "Player") { wooden_Pillar_23.transform.position = new Vector3(825.97,104.6422,1210.79); animation.rewind(woodenPillar23_anim); } } --------------------------------------------------------------- wooden_Pillar_23 is the object that I want moved back woodenPillar23_anim is the object`s animation
let me know if you need more info!
Hey I figured it out, combination of my original script plus your .Transform Position, I ended up using animation.stop
Thanks alot for your help!
Answer by Maulik2208 · Nov 30, 2012 at 10:13 AM
Public Gameobject wooden_Pillar_23;//define this in inspector
Public Animation woodenPillar23_anim;//
void OnTriggerEnter(other:Collider)
{
if (other.tag == "Player")
{
wooden_Pillar_23.transform.position = new Vector3(825.97,104.6422,1210.79);
animation.Rewind("woodenPillar23_anim");;
}
}
Your answer
Follow this Question
Related Questions
timer that can be reset 1 Answer
Animation problems 1 Answer
Can I make animations snap to a frame? 1 Answer
How can I animate a death sequence for the FPS controller? 1 Answer
How can i make the cat climb a fence? 0 Answers