我在制作死神动画时遇到了问题。
我在Unity动画制作中正确设置了动画,并使用bool isDead作为从“任何状态”改变状态的条件。去吸血鬼死亡'。
玩家角色已经附加了Animator(确实可以播放默认的飞行动画)。
我需要确保死亡动画在
中的其余逻辑之前完整播放//Game over on collision with obstacles
private void OnCollisionEnter2D(Collision2D collision)
{
...
}
被召唤。
这是我的播放器控制器脚本......
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class VampireBatController : MonoBehaviour {
//Declarations
Rigidbody2D bat;
public static int score;
public static int finalScore;
public static int highScore;
public Text scoreText;
public AudioClip flapSound;
public AudioClip crashSound;
public int batColliderIndex = 0;
public Animator myAnimator;
[SerializeField] private PolygonCollider2D[] colliders;
// Use this for initialization
void Start () {
score = 0;
bat = GetComponent<Rigidbody2D>();
myAnimator = gameObject.GetComponent<Animator>();
scoreText.text = score.ToString();
}
// Update is called once per frame
void Update()
{
//Update score display
scoreText.text = score.ToString();
Debug.Log("SCORE: " + score);
//Player input
if (Input.GetMouseButtonDown(0))
{
bat.velocity = new Vector2(0, 4);
SoundManager.instance.PlaySingle(flapSound);
}
}
//Point increment function
private void OnTriggerEnter2D(Collider2D collision)
{
if (collision.gameObject.tag == "Point" && batColliderIndex == 9)
{
score++;
return;
}
}
//Game over on collision with obstacles
private void OnCollisionEnter2D(Collision2D collision)
{
if (collision.gameObject.tag=="Skyscraper" || collision.gameObject.tag=="GroundCollider")
{
//Impact sound plays
SoundManager.instance.PlaySingle(crashSound);
//vampire_death animation plays
//I wonder why only the first frame of the animation plays?
myAnimator.SetBool("isDead", true);
finalScore = score;
Debug.Log("Game Over State Final Score: " + finalScore);
if (score >= highScore)
{
highScore = score;
}
//Send highScore to PlayerPrefs
PlayerPrefs.SetInt("savedHighScore", highScore);
Debug.Log("Game Over State HIGH SCORE: " + highScore);
//Load game over screen
SceneManager.LoadScene(2);
Debug.Log("Loading game over scene");
}
}
//Sprite collider selector by animation frame
public void SetColliderForSprite(int spriteNum)
{
colliders[batColliderIndex].enabled = false;
batColliderIndex = spriteNum;
colliders[batColliderIndex].enabled = true;
}
}
关于我出错的地方或我可以采取哪些措施来确保动画完全播放,然后继续游戏状态以外的任何其他建议?