- Home /
Problems switching animations | Please answer
First off I am a beginner with Unity and would like a simple answer with not much involved. My problem is that I have two animations: run and idle. I have parented a knife and a hand to an empty game object. I have linked the animations to the empty game object; "weapon". I have made a quick javascript which makes the run animation play when I hold down "w". When I release "w" it will play the idle animation. My problem, yes, again, is that the animations run fine but after I stop walking the idle animation plays in whatever position the GameObject was last at rather than the starting position of the animation. However, when I press "w" again, the run animation works fine with the weapon going back to the proper position.
Here is my script:
function Update()
{
if(Input.GetKeyDown("w"))
{
// Plays the animation - stops all other animations
GetComponent.<Animation>.Play("runninganim", PlayMode.StopAll);
}
if(Input.GetKeyUp("w"))
{
GetComponent.<Animation>.Play("ambientanim", PlayMode.StopAll);
}
}
Please help. Here are some images.
1: http://answers.unity3d.com/storage/attachments/47775-screen-shot-2015-06-07-at-20251-pm.png 2: http://answers.unity3d.com/storage/attachments/47774-screen-shot-2015-06-07-at-20159-pm.png
Saying 'please' won't attract much attention. - just a side note.
You should upgrade to the new animation system - it's the future of Unity. It's even easier to use. As for this system, I can't help much as I never got to learn it. (I'm quite a recent Unity user).
As for the new animation system, I have used the animation window to make the clips, and there is an error in my code saying that I need to set it to legacy. Do I use the Animator window (not animation) to make my clips ins$$anonymous$$d of coding? BTW I don't know how to use it.
No, you still create animations with the Animation tab, and then you drag the animations from your assets to the Animator. As for a tutorial, just visit the unity site. I watched some YouTube vidoes and grasped the concept in under an hour.
If you're not on Unity 5, then I recommend upgrading.
Your answer
Follow this Question
Related Questions
In-depth Animation and Audio guide for Enemy AI? 1 Answer
How would you reccommend adding the jumping animation to my script? 0 Answers
Play a simple animation once on key press 3 Answers
Animation doesn't work 1 Answer
Begginers question, Simplifing a script, opening two doors with 2 overlapping triggers. 1 Answer