Hi, I can’t seem to get my script working, which is meant to animate my sprite upon movement. Can anybody tell me what is wrong with this script? I have all of the images in the right place, it just seems to animate even when not moving.
Here is the script:
public var frameSpeed:float=0.05;
private var nextFrame:float=0;
public var sprites:Texture2D ;
private var counter:int=0;
function Update ()
{
if (Input.GetKey(KeyCode.UpArrow))
{
this.transform.Translate(Vector3.left5Time.deltaTime);
changeTexture ();
}
if (Input.GetKey (KeyCode.DownArrow))
{
this.transform.Translate (-Vector3.left5Time.deltaTime);
changeTexture ();
}
if (Input.GetKey (KeyCode.LeftArrow))
{
this.transform.Rotate(-Vector3.up100Time.deltaTime);
}
if (Input.GetKey (KeyCode.RightArrow))
{
this.transform.Rotate (Vector3.up100Time.deltaTime);
}
this.renderer.material.SetTexture (“_MainTex”, sprites[counter]);
counter++;
if (counter==sprites.Length) counter=0;
}
function changeTexture ()
{
this.renderer.material.SetTexture(“_MainTex”, sprites[counter]);
if (Time.time>nextFrame)
{
counter++;
nextFrame=Time.time+frameSpeed;
}
if (counter==sprites.Length) counter=0;
}