I’m trying to figure out a good way to have it so my player while standing around doing nothing but his idle animation after a few minutes or seconds will perform another idle animation.
Maybe even have 3 different animations that will play after each other if the player is idle for a long time.
What’s the best way to approach this?
Here’s an idea: (Warning: Untested code)
var timeForIdle : float = 5f;
var idleTimer : float;
var playIdle : boolean;
funciton Start()
{
idleTimer = timeForIdle;
}
function Update()
{
if(noInteractions && !playIdle)
{
// Frame rate dependent
idleTimer -= Time.deltaTime;
if(idleTimer <= 0)
{
idleTimer = 0;
playIdle = true;
PlayIdleAnimations();
}
}
else if(!noInteractions)
{
idleTimer = timeForIdle;
playIdle = false;
}
}
function PlayIdleAnimations()
{
if(!playIdle)
return;
animation.CrossFade("idle1");
yield WaitForSeconds(animation["idle1"].time);
animation.CrossFade("idle2");
yield WaitForSeconds(animation["idle2"].time);
animation.CrossFade("idle3");
yield WaitForSeconds(animation["idle3"].time);
}
No definition for noInteractions ???
C# Version:
float timeForIdle = 5f;
float idleTimer;
bool playIdle;
void Start()
{
idleTimer = timeForIdle;
}
void Update()
{
if(noInteractions && !playIdle)
{
// Frame rate dependent
idleTimer -= Time.deltaTime;
if(idleTimer <= 0)
{
idleTimer = 0;
playIdle = true;
PlayIdleAnimations();
}
}
else if(!noInteractions)
{
idleTimer = timeForIdle;
playIdle = false;
}
}
void PlayIdleAnimations()
{
if(!playIdle)
return;
animation.CrossFade("idle1");
yield return WaitForSeconds(animation["idle1"].time);
animation.CrossFade("idle2");
yield return WaitForSeconds(animation["idle2"].time);
animation.CrossFade("idle3");
yield return WaitForSeconds(animation["idle3"].time);
}