Looping problem

Go through this code.

var Character : Transform;
var dist = 3;

function Update(){
if ( Vector3.Distance( Character.position, transform.position ) < dist ){
if (Input.GetKey(“e”))
Character.animation.Play(“push”);
animation[“push”].wrapMode = WrapMode.Once;
}
}

I put this script on a game object say cube. The variable Character is my third person player. I have a third person character animation for pushing objects. ok. the thing is if i get near the cube and press “e” key, the player animation starts to play but it plays continuously. i want it to stop after one cycle of animation.

it looks like pushing the object again and again lol.

Is GetKeyDown() what you’re looking for?

The Problem is solved.:slight_smile:

var Character : Transform;
var AnimationToPlay = “”;
var dist = 3;

function Update(){
if ( Vector3.Distance( Character.position, transform.position ) < dist ){
if (Input.GetKey(“e”)){
Character.animation[AnimationToPlay].wrapMode = WrapMode.ClampForever;
Character.animation.Play(AnimationToPlay);

}
}
}

Brace brackets are your friend. So are tabs

var Character : Transform;
var AnimationToPlay = "";
var dist = 3;

function Update(){
      if ( Vector3.Distance( Character.position, transform.position ) < dist )
      {
            if (Input.GetKey("e"))
            {
                  Character.animation[AnimationToPlay].wrapMode = WrapMode.ClampForever;
                  Character.animation.Play(AnimationToPlay);
            }
      }
}

i guess now the tab is also a frnd… :slight_smile: