// Runs the jumping animation on the given sprite public void Jumping(SpriteRenderer sprite) { if (sprite == character) { characterStatus = AnimStatus.Jumping; } else if (sprite == shadow) { shadowStatus = AnimStatus.Jumping; } }
// Runs the idle animation on the given sprite public void Idle(SpriteRenderer sprite) { if (sprite == character) { characterStatus = AnimStatus.Idle; } else if (sprite == shadow) { shadowStatus = AnimStatus.Idle; } }
// Animates the given sprite sprite void Animate(SpriteRenderer sprite, AnimStatus status, ref float time) { if (status == AnimStatus.Running) { idleFrameNum = 0; if (time >= runningAnimationTime) { runningFrameNum++; time = 0; if (runningFrameNum > runningAnimationFrames.Length - 1) { runningFrameNum = 0; } } sprite.sprite = runningAnimationFrames[runningFrameNum]; } else if (status == AnimStatus.Jumping) { runningFrameNum = 0; idleFrameNum = 0; sprite.sprite = jumpingSprite; } else { // Idle runningFrameNum = 0; if (isIdling && time >= idleTimeBetweenEffect) { isIdling = false; idleFrameNum++; time = 0; } else if (!isIdling && time >= idleAnimationTime) { idleFrameNum++; time = 0; if (idleFrameNum > idleAnimationFrames.Length - 1) { idleFrameNum = 0; isIdling = true; } } sprite.sprite = idleAnimationFrames[idleFrameNum]; } }
public void SetAnim(AnimStatus animStatus, float time) { //Debug.Log("SetAnim animStatus=" + animStatus + " charaName=" + charaName); switch (animStatus) { case AnimStatus.WalkUp: needFrames[0] = walk_UpFrames[0]; needFrames[1] = walk_UpFrames[2]; needFrames[2] = walk_UpFrames[1]; break; case AnimStatus.WalkLeft: needFrames[0] = walk_LeftFrames[0]; needFrames[1] = walk_LeftFrames[2]; needFrames[2] = walk_LeftFrames[1]; break; case AnimStatus.WalkRight: needFrames[0] = walk_RightFrames[0]; needFrames[1] = walk_RightFrames[2]; needFrames[2] = walk_RightFrames[1]; break; case AnimStatus.WalkDown: needFrames[0] = walk_DownFrames[0]; needFrames[1] = walk_DownFrames[2]; needFrames[2] = walk_DownFrames[1]; break; case AnimStatus.Idle: needFrames[0] = idleFrames[0]; needFrames[1] = idleFrames[2]; needFrames[2] = idleFrames[1]; break; } gameObject.GetComponent <Image>().sprite = needFrames[1]; currentIndex = 0; isNeedStop = true; timeCX = time; Play(); }
// Runs the death animation on both sprites public IEnumerator Death() { justDied = true; characterStatus = AnimStatus.Dead; shadowStatus = AnimStatus.Dead; character.sprite = deathSprite; shadow.sprite = deathSprite; // Break the colliders Collider2D[] charColliders = character.GetComponents <Collider2D>(); Collider2D[] shadColliders = shadow.GetComponents <Collider2D>(); foreach (Collider2D col in charColliders) { Destroy(col); } foreach (Collider2D col in shadColliders) { Destroy(col); } // Launch the players upward a bit float horizontalPush = Random.Range(-4f, 4f); Rigidbody2D charRB = character.GetComponent <Rigidbody2D>(); Rigidbody2D shadRB = shadow.GetComponent <Rigidbody2D>(); charRB.velocity += new Vector2(horizontalPush, 6); shadRB.velocity += new Vector2(horizontalPush, -6); // Spin the players float rotationalPush = Random.Range(-360f, 360f); charRB.freezeRotation = false; shadRB.freezeRotation = false; charRB.angularVelocity = rotationalPush; shadRB.angularVelocity = rotationalPush; yield return(new WaitForSeconds(0.75f)); // Reload the level SceneManager.LoadScene(SceneManager.GetActiveScene().name); }
public void SetAnim(AnimStatus animStatus) { //Debug.Log("SetAnim animStatus=" + animStatus + " charaName=" + charaName); switch (animStatus) { case AnimStatus.WalkLeft: needFrames[0] = walk_LeftFrames[0]; needFrames[1] = walk_LeftFrames[2]; needFrames[2] = walk_LeftFrames[1]; isLoop = true; isFighting = false; times = -1; break; case AnimStatus.WalkRight: needFrames[0] = walk_RightFrames[0]; needFrames[1] = walk_RightFrames[2]; needFrames[2] = walk_RightFrames[1]; gameObject.GetComponent <Image>().sprite = needFrames[0]; isLoop = true; isFighting = false; times = -1; break; case AnimStatus.Idle: needFrames[0] = idleFrames[0]; needFrames[1] = idleFrames[2]; needFrames[2] = idleFrames[1]; isLoop = true; isFighting = true; times = -1; break; case AnimStatus.Attack: needFrames[0] = attackFrames[0]; needFrames[1] = attackFrames[2]; needFrames[2] = attackFrames[1]; if (GetComponent <RectTransform>().anchoredPosition.x < 0) { transform.DOShakePosition(1, Vector2.right * 10, 1, 0, true); } else { transform.DOShakePosition(1, Vector2.left * 10, 1, 0, true); } isLoop = false; isFighting = true; times = -1; break; case AnimStatus.AttackLoop: needFrames[0] = attackFrames[0]; needFrames[1] = attackFrames[2]; needFrames[2] = attackFrames[1]; isLoop = true; isFighting = true; times = -1; break; case AnimStatus.Bow: needFrames[0] = bowFrames[0]; needFrames[1] = bowFrames[2]; needFrames[2] = bowFrames[1]; isLoop = false; isFighting = true; times = -1; break; case AnimStatus.Magic: needFrames[0] = magicFrames[0]; needFrames[1] = magicFrames[2]; needFrames[2] = magicFrames[1]; isLoop = false; isFighting = true; times = -1; break; case AnimStatus.Hit: needFrames[0] = hitFrames[0]; needFrames[1] = hitFrames[2]; needFrames[2] = hitFrames[1]; transform.DOShakePosition(0.5f, 5, 5, 50, true); transform.GetComponent <Image>().DOColor(Color.red, 0.3f); transform.GetComponent <Image>().DOColor(Color.white, 0.3f).SetDelay(0.3f); isLoop = false; isFighting = true; times = -1; break; case AnimStatus.Death: needFrames[0] = deathFrames[0]; needFrames[1] = deathFrames[2]; needFrames[2] = deathFrames[1]; gameObject.GetComponent <Image>().sprite = needFrames[0]; isLoop = true; isFighting = true; times = -1; break; case AnimStatus.Front: needFrames[0] = walk_DownFrames[1]; gameObject.GetComponent <Image>().sprite = needFrames[0]; isLoop = true; isFighting = false; times = -1; break; case AnimStatus.ChestOpen: needFrames[0] = idleFrames[0]; needFrames[1] = idleFrames[1]; needFrames[2] = idleFrames[2]; needFrames[3] = idleFrames[3]; gameObject.GetComponent <Image>().sprite = needFrames[0]; isLoop = true; isFighting = false; times = -1; break; case AnimStatus.SpringAppear: needFrames[0] = idleFrames[0]; gameObject.GetComponent <Image>().sprite = needFrames[0]; gameObject.GetComponent <Image>().color = new Color(1f, 1f, 1f, 0f); gameObject.GetComponent <Image>().DOFade(1f, 0.5f); gameObject.GetComponent <Image>().DOFade(0f, 0.5f).SetDelay(2f); isLoop = true; isFighting = false; times = -1; break; case AnimStatus.Laugh: case AnimStatus.Surprise: case AnimStatus.SayYes: case AnimStatus.SayNo: setFrames = Resources.LoadAll <Sprite>("Image/RolePic/" + charaName + "/" + animStatus.ToString()); if (setFrames.Length > 0) { needFrames = new Sprite[setFrames.Length]; needFrames[0] = setFrames[0]; needFrames[1] = setFrames[1]; needFrames[2] = setFrames[2]; gameObject.GetComponent <Image>().sprite = needFrames[0]; isLoop = false; isFighting = false; times = (short)Random.Range(2, 4); fps = Random.Range(4f, 4.5f); } else { return; } break; } // Debug.Log(needFrames[0].texture.width + " " + needFrames[0].texture.height); if (animStatus == AnimStatus.ChestOpen) { // Debug.Log("needFrames[0].texture.width=" + needFrames[0].texture.width + " needFrames[0].texture.height=" + needFrames[0].texture.height); gameObject.GetComponent <RectTransform>().sizeDelta = new Vector2(needFrames[0].texture.width, needFrames[0].texture.height / 4f); // Debug.Log("gameObject.GetComponent<RectTransform>().sizeDelta=" + gameObject.GetComponent<RectTransform>().sizeDelta); fps = 2.5f; } else if (animStatus == AnimStatus.SpringAppear) { gameObject.GetComponent <RectTransform>().sizeDelta = new Vector2(needFrames[0].texture.width, needFrames[0].texture.height); } else { gameObject.GetComponent <RectTransform>().sizeDelta = new Vector2(needFrames[0].texture.width / (3 * 2f), needFrames[0].texture.height / 2f); fps = 10.0f; } if (animStatus != AnimStatus.Front && animStatus != AnimStatus.Death && animStatus != AnimStatus.SpringAppear) { currentIndex = 0; Play(); } else { Stop(); } }