Hi there,
I was just wondering if it was possible to access animations by their array number instead of their name?
so instead of - Character.animation.Play(“Run”);
you might have something like - Character.animation.Play[1];
I was trying to set up a scene where I could go through and check the cylces on characters quickly and it would be nice to have a var that i could just flick between.
Like this - var currentanimation : int Character.animation.Play[currentanimation];
then i could just click throught them in the inspector
That works but I have a little trouble with arrays,
I cant seem to add to them, not too sure what I am doing wrong(probably something kinda basic)
var Character : GameObject;
var AnimationNames : String[];
function Start(){
for (var state : AnimationState in Character.animation){
AnimationNames.Push(state.name);
Debug.Log(state.name);
}
}
This seems to grab the animation names fine but I can’t seem to get them to add to the “AnimationNames” Array.
Do you know what I might be doing wrong there?
I keep getting ‘Push’ is not a member of ‘(String)’.
You are using a ‘built-in’ array, which is fast, but doesn’t allow any dynamic adding/removing of objects. Functions like push and pop do not exist for it.
However, in this case you know what size it will be, so you can use it like this:
var cnt = 0;
AnimationNames = new String[Character.animation.GetClipCount()];
for (var state : AnimationState in Character.animation)
{
AnimationNames[cnt] = state.name;
cnt++;
}
Hi there- I know I’m resurecting an old and dead post, but I just can’t figure out how to use this.
I have the same issue, I would like to play my animations based on a random number and then use that to choose the anim.
So, I have this so far:
var evasiveAnimations : Animation[];
var minDexterity : int = 0;
var maxDexterity : int = 9;
function EvasiveAction()
{
evasiveMode = true;
aggressiveMode = false;
var evasiveChoice = Random.Range(minDexterity,maxDexterity);
gameObject.animation.Play(evasiveAnimations[evasiveChoice]);
}
As you discovered, this doesn’t work…but I can’t quite figure out how to implement your solution
Do you have your animations stored in the “evasiveAnimations” array?
That looks like it should work to me, are you getting an error or is it just not doing anything?
Yeah, I have them in the array, but then when i add elements to the aray via inspector, I can’t actually choose any of my animations…it just shows little “clock” symbols and some other files. Strange.
I am now trying to add an Animation component, then add in the animations to each of the elements in there, which works, however I have no idea how to call them to be played…arg.