Playing Animations

I’m trying setup a “simple” script to play an animation when pushing a button. I tried modifying a script that was setup to load a scene by changing the loadscene command to a “animation.Play” command but it doesn’t work… i guess nothing is simple. here’s what i’m using;

var nextButton : GUITexture;
var nextButtonUp : Texture;
var nextButtonDown : Texture;

var prevButton : GUITexture;
var prevButtonUp : Texture;
var prevButtonDown : Texture;

var nextScene : String;
var prevScene : String;

var clickSound : AudioClip;
var mainCamera : Camera;

//I added this section

//var animationTarget : Animation; 
//function Start(){
//	animationTarget.wrapMode = WrapMode.Loop;
//	animationTarget[ "instruct" ].wrapMode = WrapMode.ClampForever;
//	animationTarget[ "idle" ].wrapMode = WrapMode.ClampForever;




private var prevPressed : boolean;

function Update() { 
	var count = iPhoneInput.touchCount; 
	for (var i : int = 0; i < count; i++) { 
		var touch : iPhoneTouch = iPhoneInput.GetTouch(i); 

		if (touch.phase == iPhoneTouchPhase.Began) { 
			
			var prevPressed = this.prevButton.HitTest(touch.position, this.mainCamera);
			var nextPressed = this.nextButton.HitTest(touch.position, this.mainCamera);
			
			if (prevPressed) {
				// show "clicked" texture
				// play sound
				animation.Play("idle"); 
			}
			if (nextPressed) {
				animation.Play("instruck");
				// play sound
				// show "clicked" texture
			} 
		} 
	}
}

Any ideas what i’m doing wrong? should i go back to selling 44 ounce big gulps and 59 cent hot dogs at the am pm?

thanks

Well, first you should probably check and make sure that the GameObject you’ve attached this script to has an Animation component in the inspector. Try setting the default animation there, and set it to play at start with a wrapmode of loop. That’s a good basic way of checking to make sure your animation is getting imported correctly.

Once you have that going, if your button code still isn’t working, put in some Debug.Log statements inside your touch handlers to make sure they’re triggering.

It’s always a process of elimination, but try to get rid of the easy possible problems first.

Thanks… i’ll give it a shot

thanks again, the script was attached to the camera instead of the object, a left over from the previous technique.