how can i have animations randomly play? for example i have 2 idle animations, one main and one that i would like to play once through at random intervals while the character is not moving. how would i go about getting this to happen? so far i can only get the main idle animation to play.
2 Answers
2perhaps your idle animation could be controlled by a coroutine, something like this:
function Idle()
{
while (idling) {
if (Random.Range(0,5) > 0) {
animation.Play(idleClipNormal);
yield WaitForSeconds (idleClipNormal.length);
} else {
animation.Play(idleClipOccasional);
yield WaitForSeconds (idleClipOccasional.length);
}
}
}
This is what I did:
var SceletorObject : GameObject = null;
var curAnim : String = null;
var doAnimation : boolean = false;
private var AnimObj : Animation = null;
function Start(){
AnimObj=SceletorObject.GetComponent(Animation);
}
function OnTriggerEnter() {
AnimObj.PlayQueued("raise");
doAnimation=true;
}
function OnTriggerExit() {
AnimObj.PlayQueued("hit");
AnimObj.PlayQueued("die");
doAnimation=false;
}
function OnTriggerStay(){
if (!AnimObj.isPlaying && doAnimation)
doNextAnim();
}
function doNextAnim(){
var anims=new Array("idle1","idle1","idle1","idle1","idle2","strike");
var length=anims.length-1;
var index=Mathf.Round(length*UnityEngine.Random.value);
curAnim=anims[index];
AnimObj.PlayQueued(curAnim);
}
HTH
the above code assumes that you would call the function Idle() when the character should start idling. You should also have a boolean variable called 'idling' which is set to true. The function above will keep playing idle animations until you set the 'idling' boolean variable to false.
– duckWhat exactly do you need to know? The LocationInfo class already exposes the lat/lng/altitude of the device - you just need to map that to the location of your virtual character.
– tanoshimi