Animation Script

Hi,
I need help with my script…
the normal animation is played in a loop

function Update ()
{


 if(Input.GetKey("w"))
 {

	 animation.Play("WalkForward");
	 
	 }
	 else
	 {
	 animation.Play("AimIdle");
	 }
 
}

Well, there are definitely some problems with the syntax of the script, but since you neglected to mention what you’re trying to do, it’s difficult to help you…

Maybe you’re after something like this?

function Update ()
{
   if (Input.GetKey("w"))
   {
      animation.Play("WalkForward");
   }
   else
   {
      animation.Play("AimIdle");
   }
}

that is not the answer:(

there is no error in teh syntax…
the standard animation(“AimIdle”) is, when im dont press the w, in a loop

To fix the syntax you should use this:

Wow, I was prepared to argue that point, but, you’re right… I was totally thrown by the horrible alignment of the braces in your posted code. Sorry about that.

So, again, I guess I don’t understand the question…

Jeff

I thought you were making a joke. I thought that was funny…

now i have the answer…
but ive got another problem…
i want to play first the animatin “IdleWalk” and the “WalkForward”.
how should i do that?

What do you mean?

Hi,

Please explain in detail so that i can help you . I am not able to understand the problem you are facing .

i want that at first the animation"IdleWalk" is played and after this the animation “WalkForward”

Is it playing IdleWalk at all? If it’s just not looping, go to the imported file in your heirarchy and make sure it is set to loop on wrap type.

I will start initially, first of all drag the fbx model from the project view to the hierarchy view after that click the model and see its animation property in inspector view, in that property you can find the animations attribute , provide the size equals to 2 and then in elements provide both the animations,respectively. After doing this you can use your script that you mentioned above . Drag that script on the model itself and then you can check it.

Hope that will solve your problem.

and if you want that both the animations will play in loop then

function Update ()
{
        if(Input.GetKey("w"))
         {
         gameObject.animation["WalkForward"].wrapMode=WrapMode.Loop;   
	 animation.Play("WalkForward");
	 
	 }
	 else
	 {
          gameObject.animation["AimIdle"].wrapMode=WrapMode.Loop; 
	 animation.Play("AimIdle");
	 }
}

i want that when i press w down the animation “IdleWalk”
when i still press w the animation “WalkForward” should be played
when i press w up the animation “WalkIdle” should be played

I would use

function Start()
{
    animation.wrapMode = WrapMode.Loop;
}

It will loop all animations.

Ohh! I see, you want to blend from IdleWalk (a slower walk, I presume) to WalkForward (the full speed walk) the longer the player holds down the w key… like sonic the hedgehog? your naming convention is weird. you Should call it “walk”, “run” and “idle”. “IdleWalk” and “WalkIdle” is kind of confusing.

If that’s actually what your looking for, I’d do something like this:

//time delay before we start the running animation when we are moving forward
public var timeToStartRunning : float = 0.5;

private var isMoving : boolean = false;
private var timeStartedMoving : float = 0.0;

function Update(){

    //set isMoving to true when the w key is press, and false when it is released
    if(InputGetKeyDown("w")){
    	isMoving = true;
        timeStartedMoving = Time.time;  
    }
    else if(Input.GetKeyUp("w')){
    	isMoving = false;
    }
    
    if(isMoving){
    	
        //if we are moving forward and 0.5 seconds has elapsed, play the run animation
        if(Time.time > (timeStartedMoving + timeToStartRunning)){
        	animation.CrossFade("Run");
        }
        else{ //else, play the walk animation
        	animation.CrossFade("Walk");
        }
    
    }
    else{
    	
        //we are not moving, play the idle animation
        animation.CrossFade("Idle");
        
    }
    
}

IdleWalk is the blending animation from idle to walkforward and walkidle from walkforward to idle

Oh… I see. You should just use CrossFade and forget about the blending animations, that seems a bit unnecessary. Unity is very capable at blending.