当遇到不灵敏的情况时,用mAnimator.play("动画名",layer,设置0或1(如果要倒放动画就设置为1反正为0))。
下面是转换场景渐变代码
using System.Collections;
using System.Collections.Generic;
using UnityEngine;using UnityEngine.UI;
using UnityEngine.SceneManagement;public class GameManger : MonoBehaviour {
public static GameManger _instance;
public Text score;
public Text showScore;
public GameObject player;
public GameObject gameovermume;
public Animator transitionAnim;
public bool scenceiscomplet = false;
public int Mscore=0;
private AsyncOperation mAsync = null;
public bool panduan = false;
public Button backbutton;
public Button Restartbutton; // Use this for initialization private void Awake() {
_instance = this; }
void Start () { //
// transitionAnim.SetFloat("speed", -1);
Time.timeScale = 1;
transitionAnim.SetFloat("speed", -1);
transitionAnim.Play("transition",0,1);
backbutton.GetComponent().enabled = true;
}
// Update is called once per frame
void Update () {
Mscore = (int)(3.21f - player.transform.position.y);
score.text = Mscore + "米";
if (panduan)
{
TransitionAnimisPlay();//允许加载场景
}
}
public void GameOver()
{
showScore.text = " 得分:" + score.text;
gameovermume.SetActive(true);
Time.timeScale = 0;
}
public void RestartGame()
{
transitionAnim.SetFloat("speed", 1);
transitionAnim.Play("transition", 0, 0);
Restartbutton.GetComponent().enabled = false;
panduan = true;
StartCoroutine(loadScene(1));
Time.timeScale = 1;
}
public void BackMainMuem()
{
transitionAnim.SetFloat("speed", 1);
transitionAnim.Play("transition", 0, 0);
backbutton.GetComponent().enabled = false;
panduan = true;
StartCoroutine(loadScene(0));
}
public void TransitionAnimisPlay()
{
if (transitionAnim.GetCurrentAnimatorStateInfo(0).normalizedTime > 0.9 && transitionAnim.GetCurrentAnimatorStateInfo(0).IsName("transition")) {
mAsync.allowSceneActivation = true;
}
}
IEnumerator loadScene(int scence)
{
mAsync = SceneManager.LoadSceneAsync(scence);
mAsync.allowSceneActivation = false;
yield return mAsync;
}
}