简体   繁体   English

单击时,重新加载场景按钮在Unity 5.3上不起作用

[英]Reload Scene Button doesn't work on Unity 5.3 when clicked

I need some help or I think I'm missing something on my script. 我需要一些帮助,或者我认为我的脚本中缺少某些内容。

I created a GUI Button, created my c# script and attached it to the “Canvas” gameobject. 我创建了一个GUI按钮,创建了c#脚本,并将其附加到“画布”游戏对象上。

Then on my button created the On Click() event as you can view it on the following image: 然后在我的按钮上创建On Click()事件,您可以在以下图像上查看它:

GUI Button GUI按钮

And here is my script: 这是我的脚本:

using UnityEngine;
using System.Collections;
using UnityEngine.SceneManagement;

public class RestartLvl : MonoBehaviour {

    void Start () {

    }

    void Update () {

    }

    void OnMouseDown() {
        ReloadCurrentScene();
    }

    public static void ReloadCurrentScene() {

            string sceneName = SceneManager.GetActiveScene().name;
            SceneManager.LoadScene(sceneName, LoadSceneMode.Single);
    }


}

So when I press the button nothing happens, please help! 因此,当我按下按钮时,什么都没有发生,请帮忙! Thanks! 谢谢!

You don't need to use OnMouseDown() since you are already calling the ReloadCurrentScene() in that button OnClick event. 您不需要使用OnMouseDown(),因为您已经在该按钮的OnClick事件中调用了ReloadCurrentScene()。

But the onclick event target has error message, , so you'll to fix that, might work if you just re-select it from that dropdown. 但是onclick事件目标具有错误消息,因此,如果您从该下拉列表中重新选择它,则可以解决此问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM