Unity Error CS0126

本文关键字:CS0126 Error Unity | 更新日期: 2023-09-27 18:26:10

我确信这是一件愚蠢而简单的事情,但我无法弄清楚。以下代码:

public GameObject AISelectCannon() {
    Debug.Log("AISelectCannon called");
    GameObject desiredCannon = AIController.selectCannon(0);
    if (desiredCannon.tag.Contains("Cannon")) return;
    m_SelectedCannon = desiredCannon;
    aiSelectionPending = true;
    return m_SelectedCannon;
}

正在引发以下错误:

Scripts/CubeContainer.cs(61,59): error CS0126: An object of a type convertible to `UnityEngine.GameObject' is required for the return statement

(GameObject设计的Cannon…是第61行)

来自AIController的其他相关信息:

public static GameObject selectCannon(int side) {

是的,有什么想法吗?

Unity Error CS0126

您的第一个return语句没有返回任何内容,它只是说返回

if (desiredCannon.tag.Contains("Cannon")) return // return something