Search code examples
c#genericsunity-game-enginegoogle-vr

Unity CS0308 error: The non-generic method cannot be used with the type arguments


I have trying to build a game in Unity3D and I am using Unity 5.1.1 pro version, I have imported Google VR sdk, and I am getting this error.

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

Solution

  • you can use Component.GetComponentsInChildren because it takes a boolean value to include the inactive objects, but because it returns an array you can use an ForEach to assign your variable to each element

     public VideoControlsManager[] VideoControlsManagers;
    VideoControlsManagers = GetComponentsInChildren<VideoControlsManager>(true);
    
            foreach( VideoControlsManager v in VideoControlsManagers )
                v.Player  = player;