using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class zjl_wupindianji : MonoBehaviour { public GameObject tu1; public GameObject UI; float time = 0.2f; bool isInvoke = false; // Start is called before the first frame update void Start() { //tu1 = GameObject.Find("toushiyanjing"); tu1.SetActive(false); UI.SetActive(false); } // Update is called once per frame void Update() { } void OnMouseDown() { Destroy(this.gameObject); UI.SetActive(true); Invoke("close", 1f); //isInvoke = true; tu1.SetActive(true); } void close() { UI.SetActive(false); } }为啥这段代码的invoke不调用
时间: 2024-02-14 10:33:44 浏览: 39
根据您提供的代码,我没有看到任何明显的问题。您可以尝试在控制台中打印一些调试信息以帮助诊断问题:
1. 确保您在调用Invoke方法之前已经在控制台中打印了一些信息,以确保代码执行到该点。
2. 在调用Invoke方法之后,在控制台中打印一些信息,以确保Invoke方法已经被调用。
如果您仍然无法解决问题,请尝试使用另一种方法来实现您的需求,例如使用coroutine或直接在Update方法中实现需要的逻辑。
相关问题
using System.Collections; using System.Collections.Generic; using UnityEngine; public class likai : MonoBehaviour { public void Quit() { debug"你好"; Application.Quit(); } }
这段代码中有一个语法错误,正确的代码应该是这样的:
```csharp
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class likai : MonoBehaviour {
public void Quit()
{
Debug.Log("你好");
Application.Quit();
}
}
```
我做了以下修改:
1. 加了一些空行,使代码更易读。
2. 将`debug`改为`Debug.Log`,因为Debug是一个类,它的方法需要用点号来调用。
3. 将`Debug.Log("你好")`用双引号括起来,因为在C#中,字符串需要用双引号或单引号括起来。
这样,代码就可以正确编译并运行了。
解释下面代码:using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI;
这段代码是C#语言中的using命令,用于导入不同的命名空间,以便在代码中使用该命名空间中的类和成员。具体解释如下:
- using System.Collections;:导入System.Collections命名空间,该命名空间包含了各种集合类,如ArrayList、Hashtable、Queue等。
- using System.Collections.Generic;:导入System.Collections.Generic命名空间,该命名空间包含了各种泛型集合类,如List、Dictionary等。
- using UnityEngine;:导入UnityEngine命名空间,该命名空间包含了Unity引擎的各种类和成员,如GameObject、Transform、Camera等。
- using UnityEngine.UI;:导入UnityEngine.UI命名空间,该命名空间包含了Unity引擎中的UI相关类和成员,如Button、Text、Image等。