// Updates UnityAnim anim type // Returns true if anim is over private static bool UpdateUnityAnim(UnityAnim unityAnim) { bool bAnimComplete = false; if (!unityAnim.targetObj.GetComponent <Animation>().IsPlaying(unityAnim.animName)) { // Infinite loop if (unityAnim.loopCount == 0) { unityAnim.targetObj.GetComponent <Animation>().Play(unityAnim.animName); } // Finite loop count else { if (unityAnim.curLoopIndex == unityAnim.loopCount) { bAnimComplete = true; } else { unityAnim.curLoopIndex++; unityAnim.targetObj.GetComponent <Animation>().Play(unityAnim.animName); } } } return(bAnimComplete); }
// public static RotateTo RotateAroundAxis(GameObject targetObj, Vector3 angle, Vector3 axis, float animSpeed, int loopCount) // { // return null; // } // Create and return UnityAnim object // targetObj - Object on which the animation clip has to be played // animName - animation clip name // loopCount - loopCount for animation // startDelay - delay after which the animation clip should be played public static UnityAnim UnityAnim(GameObject targetObj, string animName, int loopCount, float startDelay) { UnityAnim newAnim = new UnityAnim(); newAnim.targetObj = targetObj; newAnim.animName = animName; newAnim.loopCount = loopCount; newAnim.startDelay = startDelay; Animation animComponent = targetObj.GetComponent <Animation>(); // If there is no Animation component on targetObj, add one. if (animComponent == null) { animComponent = targetObj.AddComponent <Animation>(); } return(newAnim); }