如何关闭场景过渡动画
如何关闭场景过渡动画? 我想仅禁用RISTARTGAME命令的动画。使动画适用于其他命令。 有这样的脚本吗? 这是我的动画脚本:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class LevelLoader : MonoBehaviour
{
public Animator transition;
public float transitionTime = 1f;
public void LoadNextLevel()
{
StartCoroutine(LoadLevel(SceneManager.GetActiveScene().buildIndex + 1));
}
public AudioClip impact;
IEnumerator LoadLevel(int LevelIndex)
{
transition.SetTrigger("Start");
yield return new WaitForSeconds(transitionTime);
SceneManager.LoadScene(LevelIndex);
yield return new WaitForSeconds(0.3f);
AudioSource.PlayClipAtPoint(impact, transform.position);
}
}
这是我的RistartGame命令,它在另一个脚本中:
public void RestartGame()
{
SceneManager.LoadScene(PlayerPrefs.GetInt("SavedScene"));
}
How to turn off scene transition animations?
I would like to disable the animation ONLY for the RestartGame command. so that the animation works for other commands.
Is there any script for such a thing?
this is my animation script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class LevelLoader : MonoBehaviour
{
public Animator transition;
public float transitionTime = 1f;
public void LoadNextLevel()
{
StartCoroutine(LoadLevel(SceneManager.GetActiveScene().buildIndex + 1));
}
public AudioClip impact;
IEnumerator LoadLevel(int LevelIndex)
{
transition.SetTrigger("Start");
yield return new WaitForSeconds(transitionTime);
SceneManager.LoadScene(LevelIndex);
yield return new WaitForSeconds(0.3f);
AudioSource.PlayClipAtPoint(impact, transform.position);
}
}
and this is my RestartGame command which is in another script:
public void RestartGame()
{
SceneManager.LoadScene(PlayerPrefs.GetInt("SavedScene"));
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在您的实际代码中,重新启动游戏方法不使用de Animation,但是如果您在场景启动时在场景上有一个动画,则可以在加载场景之前保存playerpref变量,然后在加载场景之前,然后在该变量之前检查变量动画片。
例如:
然后在新场景的开始
In your actualy code, the RestartGame method don't use de animation, but if you have an animation on your scene when this starts, you can save a PlayerPref variable inside the RestartGame method before load the scene, and then check the variable before the animation.
For example:
then in the start of the new scene
您可以将另一个选项添加到控制动画的Ienumerator。
现在将其设置为true当重新启动并对其他情况下进行错误。在LoadNextlevel上:
You can add another option to IEnumerator that controls the animation.
Now set it to true when restart and false to other cases. On LoadNextLevel: