- Home /
Another "Animation.Play() not working" question!
Screen Game script
void Awake ()
{
btnAbilities = (GameObject)Instantiate(Resources.Load("Prefab/screen/btnRound"));
btnAbilities.transform.parent = gameObject.transform;
btnAbilities.transform.localPosition = new Vector3(0, -2, 0);
btnAbilities.GetComponent<Btn>().AssignAnimations("Animations/abilitiesIdle", "Animations/abilitiesActive");
}
Btn script
public void AssignAnimations(string idle, string active)
{
animation.AddClip((AnimationClip)Resources.Load(idle, typeof(AnimationClip)), "idle");
animation.AddClip((AnimationClip)Resources.Load(active, typeof(AnimationClip)), "active");
animation.Play("idle");
//animation.CrossFade("idle", 0);
}
Both clips appear on Animation inspector.
abilitiesIdle Wrap Mode is set to Loop, abilitiesActive Wrap Mode is set to Once.
No warnings, no errors.
What am I missing?
Not sure if this is at all related to your issue, but why are you "assigning" your animations the way you are? It would make much more sense to just drag and drop these animation clips into the Animation window. Also in the first part, I don't believe that the Resource.Load calls are at all necessary when instantiating your prefab. You can just call the prefab name directly, by declaring a public variable and dragging + dropping the prefab into the slot.
At the end there will be 8 buttons, and maybe in time I will add more. Adding all the clips was an idea, but I don't like having 14 unused clips on each button. $$anonymous$$y plan is to load all animations in one folder to avoid "declaring a public variable and dragging + dropping the prefab into the slot" when a new button is added.
Thank you for your suggestions.
"$$anonymous$$y plan is to avoid declaring a public variable and dragging + dropping the prefab into the slot" - while it may not seem intuitive at first, that is the "Unity" way of doing things, and you may find it easier to work with it rather than fight against it.