- Home /
Help Error CS0111
Help I am a begin coder and i keep getting this error that I don't know how to fix.
here's my code:
using UnityEngine;
using System.Collections;
public class NetworkManger : MonoBehaviour {
SpawnSpot[] spawnSpots;
public bool offlineMode = false;
bool conecting = false;
ArrayList chatMessages;
int maxChatMessages = 5;
string roomName = "Room01";
int maxPlayer = 1;
string maxPlayerString = "1";
Room[] game;
Vector2 ScrollPosition;
// Use this for initialization
void Start () {
spawnSpots = GameObject.FindObjectsOfType<SpawnSpot>();
PhotonNetwork.player.name = PlayerPrefs.GetString("Username", "Guest");
chatMessages = new ArrayList();
}
void OnDestroy() {
PlayerPrefs.SetString("Username", PhotonNetwork.player.name);
}
public void AddChatMessage(string m) {
GetComponent<PhotonView> ().RPC ("AddChatMessage_RPC", PhotonTargets.All, m);
}
[RPC]
void AddChatMessage_RPC(string m) {
while(chatMessages.Count >= maxChatMessages) {
chatMessages.RemoveAt (0);
}
chatMessages.Add(m);
}
void Connect() {
PhotonNetwork.ConnectUsingSettings ("1.0.0");
}
void OnGUI() {
GUILayout.Label( PhotonNetwork.connectionStateDetailed.ToString() );
if (PhotonNetwork.connected == false && conecting == false) {
GUILayout.BeginArea (new Rect (0, 0, Screen.width, Screen.height));
GUILayout.BeginHorizontal ();
GUILayout.FlexibleSpace ();
GUILayout.BeginVertical ();
GUILayout.BeginHorizontal ();
GUILayout.Label ("User Name");
PhotonNetwork.player.name = GUILayout.TextField (PhotonNetwork.player.name);
GUILayout.EndHorizontal ();
if(GUILayout.Button ("Sgin In")) {
Connect();
conecting = true;
}
if(GUILayout.Button ("Play as Guest")) {
Connect();
conecting = true;
PhotonNetwork.player.name = ("Guest");
}
if(GUILayout.Button ("Exit")) {
Application.Quit();
}
GUILayout.FlexibleSpace();
GUILayout.EndVertical();
GUILayout.FlexibleSpace();
GUILayout.EndHorizontal();
GUILayout.EndArea();
}
if(PhotonNetwork.connected == true && conecting == false) {
GUILayout.BeginArea(new Rect (0, 0, Screen.width, Screen.height));
GUILayout.BeginVertical();
GUILayout.FlexibleSpace();
foreach(string msg in chatMessages) {
GUILayout.Label(msg);
}
GUILayout.EndVertical();
GUILayout.EndArea();
}
}
void OnJoinedLobby() {
Debug.Log ("OnJoinedLobby");
PhotonNetwork.JoinRandomRoom();
}
void OnPhotonRandomJoinFailed() {
Debug.Log ("OnPhotonRandomJoinFailed");
PhotonNetwork.CreateRoom( null );
}
void OnJoinedRoom() {
Debug.Log ("OnJoinedRoom");
}
void OnGUI() {
GUILayout.Label ("Welcome: " + PhotonNetwork.player.name);
GUILayout.Label ("Room Name:");
roomName = GUILayout.TextField ("Room Name"); //For network room name ask and recieve
GUILayout.Label ("Max Amount of player 1-20:");
maxPlayerString = GUILayout.TextField (maxPlayerString, 2);
if (maxPlayerString != "") { // if there is a character of max players
maxPlayer = int.Parse(maxPlayerString); // parse the max player text field into a string.
if (maxPlayer > 20) maxPlayer = 20; // if I enter above 20 reset the max to 20 .
if (maxPlayer == 0) maxPlayer =1; // if i'm below 1 reset min of 1
}
if (GUILayout.Button ("Create Room")) {
if (roomName != "" && maxPlayer > 0) { // if the room name has a name and max players are larger then 0
PhotonNetwork.CreateRoom (roomName, true, true, maxPlayer);// then create a photon room visible
SpawnMyPlayer();
conecting = false;
}
}
GUILayout.Space(20);
GUI.color = Color.red;
GUILayout.Box("Game Rooms");
GUI.color = Color.white;
GUILayout.Space(20);
scrollPosition = GUILayout.BeginScrollView(scrollPosition, false ,true, GUILayout.Width(400), GUILayout.Height(300));
foreach ( RoomInfo game in PhotonNetwork.GetRoomList()) // Each RoomInfo "game" in the amount of games created "rooms" display the fallowing.
{
GUI.color = Color.green;
GUILayout.Box(game.name + " " + game.playerCount + "/" + game.maxPlayers); //Thus we are in a for loop of games rooms display the game.name provide assigned above, playercount, and max players provided. EX 2/20
GUI.color = Color.white;
if (GUILayout.Button("Join Room") ) {
PhotonNetwork.JoinRoom(game.name); // Next to each room there is a button to join the listed game.name in the current loop.
SpawnMyPlayer();
conecting = false;
}
}
GUILayout.EndScrollView();
GUILayout.EndArea();
}
void SpawnMyPlayer() {
AddChatMessage("Spawning Player: " + PhotonNetwork.player.name);
if(spawnSpots == null) {
Debug.LogError ("001");
return;
}
SpawnSpot mySpawnSpot = spawnSpots[ Random.Range (0, 1) ];
GameObject myPlayerGO = (GameObject)PhotonNetwork.Instantiate("Player", mySpawnSpot.transform.position, mySpawnSpot.transform.rotation, 0);
((MonoBehaviour)myPlayerGO.GetComponent("FPSInputController")).enabled = true;
((MonoBehaviour)myPlayerGO.GetComponent("MouseLook")).enabled = true;
((MonoBehaviour)myPlayerGO.GetComponent("PlayerShooting")).enabled = true;
myPlayerGO.transform.FindChild("Main Camera").gameObject.SetActive(true);
}
}
It is a Compiler Error CS0111
It is thrown when a class contains two member declarations with the same name and parameter types.
While posting a question also post the exact error message from console as it contains valuable information like line number.
Answer by Kiwasi · Feb 19, 2015 at 09:18 AM
You've got OnGUI declared twice with the same parameters. This is not allowed. Either delete one entirely, or copy the contents of one into the other.
Your answer
Follow this Question
Related Questions
Help Ship Controll 0 Answers
how can i get a pause screen to work 0 Answers
Trying to make Collider Activate with key code 1 Answer
How do I make my player face the direction its moving. 0 Answers
Changing Force of object 1 Answer