Tuesday, June 28, 2011

How to play an animation all the way through on a single key


======================================================================================================================================================


var die1 : boolean;
var die2 : boolean; 
function Update() 
{
 if (Input.GetKeyDown(KeyCode.Alpha1))
 { die1 = true; 
die2 = false; 
if (die1) 
{
 animation.CrossFade("die1"); 
animation.wrapMode = WrapMode.ClampForever; 
if (Input.GetKeyDown(KeyCode.Alpha2)) 
{ die2 = true; die1 = false; }
 if (die2)
 { animation.CrossFade("die2"); 
animation.wrapMode = WrapMode.ClampForever; }
 else { 
animation.CrossFade("idle"); 
animation.wrapMode = WrapMode.Loop;
 } 
}

==================================================================================================================================================
if (die1) 
{
 if(animation.IsPlaying("die1"))
{ }
else
{
 animation.Play("die1"); 
}
==================================================================================================================================================
the above code can be used to get an animation to play out fully without stopping on a single key press and even when you press the key again it shouldn't play, just double check that my "IsPlaying" method is used correctly

====================================================================================================================================================================
This seems to work just fine. Thank you all for your help.
==========================================================================================================================================================================================================================================================================================

function Start() 
animation["die1"].layer = 1; 
animation["die2"].layer = 1;
 } 
function Update() 
if (Mathf.Abs(Input.GetAxis("Vertical")) > 0.2)
 { 
animation.Stop("die1");
 animation.Stop("die2");
 if (Mathf.Abs(Input.GetAxis("Run")) > 0.2) 
{
 animation.CrossFade("run"); } 
else 
animation.CrossFade("walk");
 } } 
else if 
(Input.GetButton("Fire1"))
 {
 animation.Stop("die1");
 animation.Stop("die2"); 
animation["attack1"].wrapMode = WrapMode.Once; animation.Play("attack1"); 
else if (Input.GetButton("Fire2")) 
animation.Stop("die1");
 animation.Stop("die2");
 animation["attack2"].wrapMode = WrapMode.Once;
 animation.Play("attack2"); 

else if (Input.GetKeyDown(KeyCode.Alpha1)) 
animation["die1"].wrapMode = WrapMode.ClampForever; 
animation.CrossFade("die1"); 
else if (Input.GetKeyDown(KeyCode.Alpha2))
 {
 animation["die2"].wrapMode = WrapMode.ClampForever; animation.CrossFade("die2"); 
} else { animation.CrossFade("idle"); 
}
 }
===========================================================================================================================================================

No comments:

Post a Comment