/// <summary> /// Sets the desired animation by string name. It does some parsing on the string to account for case and typos. /// Animations are better as strings for ease of use. Avoid enums here unless there's a good reason. /// </summary> /// <param name="animationName">Animation name.</param> /// <param name="startFrame">Integer Start Frame.</param> public void SetAnimation(string animationName, bool waitForEndOfFrame = true, int startFrame = 0) { if (CurrentAnimation.animationName.ToLower().Trim().Replace(" ", "") == animationName.ToLower().Trim().Replace(" ", "")) { return; //Animation is already set to this. } if (!waitForEndOfFrame) //we want the animation to start fast { NextFrameTime = CurrentFrameTime; } foreach (FF_Animation anim in Animations) { if (animationName.ToLower().Trim().Replace(" ", "") == anim.animationName.ToLower().Trim().Replace(" ", "")) //account for mistypes { CurrentAnimation = anim; NextAnimationFrameNumber = startFrame; return; } } }
void Start() { SpriteRenderRef = this.gameObject.GetComponent <SpriteRenderer> (); CurrentAnimation = Animations [0]; SetAnimation(DefaultAnimation); }