animate scripting in new unity 2d toolkit

hi guys , i did it with changing the offset of material in older versions of unity , but now it seems that somethings have been changed…new 2d toolkit…
and im ready to change too …! so would anyone tell me plz that how can i code the sprite parts for animating , for example if the player pressed the right arrow some frames play , and if …
ofcourse ive seen some videos in youtube but none of them tell anything about scripting the frame selection , so …
this was my code for changing the material offset…

function aniSprite (columnSize, rowSize, colFrameStart, rowFrameStart, totalFrames, framesPerSecond)// function for animating sprites
{
	var index : int = Time.time * framesPerSecond;													// time control fps
	index = index % totalFrames;																	// modulate to total number of frames
	
	var size = Vector2 (1.0 / columnSize, 1.0 / rowSize);											// scale for column and row size
	
	var u = index % columnSize;																		// u gets current x coordinate from column size
	var v = index / columnSize;																		// v gets current y coordinate by dividing by column size
	
	var offset = Vector2 ((u + colFrameStart) * size.x,(1.0 - size.y) - (v + rowFrameStart) * size.y); // offset equals column and row
	
	renderer.material.mainTextureOffset = offset;													// texture offset for diffuse map
	renderer.material.mainTextureScale  = size;														// texture scale  for diffuse map
	
	//renderer.material.SetTextureOffset ("_BumpMap", offset);										// texture offset for bump (normal map)
//renderer.material.SetTextureScale  ("_BumpMap", size);											// texture scale  for bump (normal map) 
}

thanx and more

i can set the condition over variables and change the animate state :slight_smile:
thanx from myself and you too