unity change different animations every 3 sencond

March 1, 2013   ·   0 Comments

best way to change animation every 3 seconds, it will demo, 3 second walking, and next 3 second idel, after 3 second jump

// Update is called once per frame
	void Update () {
		
		try{
			if(target!=null){ 
				
		if(isAIWorking==false)  {
				StartCoroutine(Fun_AI());
		}
			}
		}catch{}
		
	}
	private bool isAIWorking=false;
IEnumerator Fun_AI(){
		isAIWorking=true;
		
		
		if(characterController==null) { yield  return null;}
		if(target==null){ yield  return null;}
        // 先發呆幾分鐘
//		PlayWithOptions(idle,0.1f);
		
		if (idleSound)
	    {
			if (audio.clip != idleSound)
			{
			//	audio.Stop();
				audio.clip = idleSound;
				audio.loop = true;
				audio.Play();	// play the idle sound.
			}
		}
	//	 animation.Play(jump);
	//		animation.CrossFade(idle);
		
		
		
		 animation.wrapMode = WrapMode.Loop;
 
 //  animation.Play(idle);
		
	animation.CrossFade(idle,0.2f);
		
	// Don't do anything when idle
	// The perfect time for the player to attack us
		 print(Time.time);
	    yield  return new  WaitForSeconds(idleTime);
		
		 animation.wrapMode = WrapMode.Loop;
 
  // animation.Play(walk);
 
		
		
	animation.CrossFade(walk,0.2f);
		 print(Time.time);
	    yield  return new  WaitForSeconds(idleTime);
		
		
		
		 animation.wrapMode = WrapMode.Once;
		
   animation.Play(gothit);
//		 animation.CrossFade(gothit);
		 print(Time.time);
   yield  return new  WaitForSeconds(idleTime);
		
//        while (animation.isPlaying) { yield return null; }
		
		
		
		isAIWorking=false;
}ation.wrapMode = WrapMode.Once;
		
   animation.Play(gothit);
//		 animation.CrossFade(gothit);
		 print(Time.time);
   yield  return new  WaitForSeconds(idleTime);
		
//        while (animation.isPlaying) { yield return null; }
		
		
		
		isAIWorking=false;
}
	
shareShare on FacebookShare on Google+Share on LinkedInEmail this to someonePrint this pageBuffer this pageDigg thisFlattr the authorShare on RedditPin on PinterestShare on StumbleUponShare on TumblrTweet about this on Twitter

By


Readers Comments (0)


You must be logged in to post a comment.

PowenKo’s Online Store

powenko_arduinoBook
Unity3D4

Amazon

adsbygoogle

Recent Posts

Categories

Amazon