Unity Error CS0126

时间:2014-10-11 04:15:43

标签: c# unity3d

我确信这很简单,但我无法理解。以下代码:

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 desiredCannon ....是第61行)

AIController的其他相关信息:

public static GameObject selectCannon(int side) {

所以是的,任何想法?

1 个答案:

答案 0 :(得分:0)

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

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