Animation Problem

Hi i’m new to animation so can some on help me with this script

if (Input.GetKeyDown (“w”)) {
animation.Play (“walk”);

}

I want when i press w it plays animation but on key up animation stops

and can some one help me with the script
when i press two times “w” animation plays “run”
thank you :smile:

Come on nobody…

Hey,

There are many ways to handle this problem.

Personally I would,

if (Input.GetAxis("Vertical") > 0.2)
       animation.CrossFade ("walk");

This took me a bit to figure out, in unity they setup buttons as default inputs. “Vertical” is positive when “w” is pressed and negative when “s” is pressed. You can find this in edit->project settings->input and look under vertical or horizontal. That iss not the best explanation of how it works but coupled with the unity references you should be able to figure it out.

As far as getting the run animation to work for you, I prefer a toggle or a hold button over a double click. To use a double click I’d imagine you’d need to use a counter and then use a reset for that counter which probably would require a yield which is getting much more in depth than needed.

So take the above code and,

if (Input.GetAxis("Vertical") > 0.2)
{
       if(Input.GetButtonDown("jump")
             animation.CrossFade("run");
       else
             animation.CrossFade ("walk");
}

Below is the reference page for animation scripting it is extremely useful, I really recommend getting comfortable with all of the Unity documentation, all of it is extremely helpful.
http://unity3d.com/support/documentation/Manual/Animation%20Scripting.html

Also there are alot of really useful tutorials all over the place.

One of my favorites is on 3DBuzz.com

Another is the Lerpz tutorial,

GOOD LUCK! Hope this helped.

I should have noted that the “jump” button is defaulted to the space bar. You’ll see this in the input settings!

Thanx man you really helped me wold you like to work with me on this project i just started so tell me if you want and i’ll give you the site where you can download my project.

Hmm, I do love working on projects however I currently work 50 hours a week and would only be able to work on any projects on weekends. If I may be so bold what kind of project are you working on?

First i was thinking of making game like Gothic 2 but nobody wanted to help me on it, and i don’t know a lot about animation,scripting so i was thinking something like this shooting and i don’t have some characters to make some cool game…And if you need some models tell me maybe i can get you something.

482815–16946–$untitled.bmp (1.03 MB)

And do you know how to make this rocket shoot at one point cause i tried some things it didn’t work.

I am definitly not a modeler, I can do the coding but not the modeling.

As far as shooting a rocket, goes the easiest way is to create a rocket object, make a script that makes it go forward infinitely and after some amount of units disappear, use raycasting to detect collisions. Have a particle emitter coming out of the back of it for the smoke effect. Then when the player clicks the “fire1” button have it instantiate that prefab at the end of the gun and give it a delay so they cant go to town and fire a bazillion rockets at a time.

I have written a script for that yet but that is the gist of what you would have to do.

Thanx it works now.

Sorry for all questions but do you know script how do i make my robot follow my mouse or rotate .

Have you tried the third person controller script that is in the standard assets?

That is not something I have really attempted, it all depends on how you want to handle your robots operations. You can get your mouse position and divide it by the screen size and use that for the rotation or the tracking.