如何关闭场景过渡动画

发布于 2025-02-01 17:48:04 字数 1019 浏览 4 评论 0原文

如何关闭场景过渡动画? 我想仅禁用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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

水水月牙 2025-02-08 17:48:04

在您的实际代码中,重新启动游戏方法不使用de Animation,但是如果您在场景启动时在场景上有一个动画,则可以在加载场景之前保存playerpref变量,然后在加载场景之前,然后在该变量之前检查变量动画片。

例如:

public void RestartGame()
{
    PlayerPrefs.SetInt("isRestarting",1);
    SceneManager.LoadScene(PlayerPrefs.GetInt("SavedScene"));
}

然后在新场景的开始

void Start ()
{
    if(PlayerPrefs.GetInt("isRestarting",0)!=1)
    {
      //Do the animation
    }

}

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:

public void RestartGame()
{
    PlayerPrefs.SetInt("isRestarting",1);
    SceneManager.LoadScene(PlayerPrefs.GetInt("SavedScene"));
}

then in the start of the new scene

void Start ()
{
    if(PlayerPrefs.GetInt("isRestarting",0)!=1)
    {
      //Do the animation
    }

}
隐诗 2025-02-08 17:48:04

您可以将另一个选项添加到控制动画的Ienumerator。

IEnumerator LoadLevel(int LevelInde, bool hasAnimation = true)
{
    if (hasAnimation)
    {
        transition.SetTrigger("Start");
        yield return new WaitForSeconds(transitionTime);
    }
    SceneManager.LoadScene(LevelIndex);
    yield return new WaitForSeconds(0.3f);
    AudioSource.PlayClipAtPoint(impact, transform.position);
}

现在将其设置为true当重新启动并对其他情况下进行错误。在LoadNextlevel上:

StartCoroutine(LoadLevel(SceneManager.GetActiveScene().buildIndex + 1, false));

You can add another option to IEnumerator that controls the animation.

IEnumerator LoadLevel(int LevelInde, bool hasAnimation = true)
{
    if (hasAnimation)
    {
        transition.SetTrigger("Start");
        yield return new WaitForSeconds(transitionTime);
    }
    SceneManager.LoadScene(LevelIndex);
    yield return new WaitForSeconds(0.3f);
    AudioSource.PlayClipAtPoint(impact, transform.position);
}

Now set it to true when restart and false to other cases. On LoadNextLevel:

StartCoroutine(LoadLevel(SceneManager.GetActiveScene().buildIndex + 1, false));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文