Unity CS0308错误:非泛型方法不能与类型参数一起使用

时间:2017-02-19 09:23:17

标签: c# generics unity3d google-vr

我试图在Unity3D中构建一个游戏,我使用的是Unity 5.1.1专业版,我已经导入了Google VR sdk,我收到了这个错误。

void Awake() {
#if !UNITY_5_2
         // im getting a error on this line 
        GetComponentInChildren<VideoControlsManager>(true).Player = player;
#else
    GetComponentInChildren<VideoControlsManager>().Player = player;
#endif
  }
}

2 个答案:

答案 0 :(得分:0)

根据documentation的第一行,没有<generictype>可接受。但该示例使用<generictype>。您可以提交一张票,看看哪个是正确的。由于错误,我怀疑定义行是写它的正确方法。所以......

以这种方式写你的行:

GetComponentInChildren(typeof(VideoControlsManager)).Player = player;

答案 1 :(得分:0)

你可以使用Component.GetComponentsInChildren,因为它需要一个布尔值来包含非活动对象,但因为它返回一个数组,你可以使用ForEach将变量分配给每个元素

 public VideoControlsManager[] VideoControlsManagers;
VideoControlsManagers = GetComponentsInChildren<VideoControlsManager>(true);

        foreach( VideoControlsManager v in VideoControlsManagers )
            v.Player  = player;
相关问题