- Home /
Cannot Convert type UnityEngine.Networking.PlayerController to PlayerController
So i'm using the Lobby Manager that is on the asset store by Unity. And in the lobbymanager.cs script there is a problem that just occured to me. it's not been there before and i dont know whats causing it. The error is in the title. And it's about this peice of code:
//allow to handle the (+) button to add/remove player
public void OnPlayersNumberModified(int count)
{
_playerNumber += count;
int localPlayerCount = 0;
foreach (PlayerController p in ClientScene.localPlayers)
localPlayerCount += (p == null || p.playerControllerId == -1) ? 0 : 1;
addPlayerButton.SetActive(localPlayerCount < maxPlayersPerConnection && _playerNumber < maxPlayers);
}
My project is kindoff on hold atm because if this wich sucks.
Answer by Waka-Takaki · Jun 13, 2016 at 07:10 AM
Your error is telling you that you're trying to convert Unity.Networking.PlayerController to a different type called PlayerController.
Have you got another script called PlayerController in your project, aside from the one in unity networking?
....... That was the issue. There is another script I added called PlayerController. Creds to you man. I appreciate that.
So, we can't name our script PlayerController if we a re using the Lobby asset right?
Long live "Find and Replace" : )
Yes you can, but you have to declare it in your own namespace
... or if you declare it in the global namespace you always have to use UnityEngine.Networking.PlayerController
whenever you need to use Unity's "PlayerController" class.
However it's best to not use a name that is already used by another script / component. You still might run into issues. While AddComponent with a string argument has been deprecated, GetComponent still exists in the string version. So having two component classes with the same name still might cause problems, even when you use namespaces.
Though in the case of "PlayerController" it shouldn't be an issue since PlayerController is not a component ^^.