- Home /
C# script help?
I get a total of 9 errors from this script. Here is an image of the errors I got:
(And here is the script which has these errors, may someone please fix it?)
using UnityEngine; using System.Collections;
public class MenuManager : MonoBehaviour { public string CurrentMenu;
public string MatchName = "";
public string MatchPassword = "";
public int MaxmatchPlayers = 32;
void Start()
{
CurrentMenu = "Main";
}
void OnGUI()
{
if(CurrentMenu == "Main")
Menu_Main();
if(CurrentMenu == "Lobby")
Menu_Lobby();
if(CurrentMenu == "Host")
Menu_HostGame();
}
public void NavigateTo(string nextmenu)
{
CurrentMenu = nextmenu;
}
private void Menu_Main()
{
if(GUI.Button(new Rect(10, 10, 200, 50), "Host game"))
{
NavigateTo("Host");
}
}
private void Menu_HostGame()
{
//Buttons Host Game
if(GUI.Button(new Rect(10, 10, 50, 50), "back"))
{
NavigateTo("Main");
}
if(GUI.Button(new Rect(60, 10, 200, 50), "Start Server"))
{
}
GUI.Label(new Rect(300, 10, 130, 30), "Match Name");
MatchName = GUI.TextField(new Rect(400, 10,200, 30), MatchName);
GUI.Label(new Rect(300, 50, 130, 30), "Match Password");
MatchPassword = GUI.PasswordField(new Rect(400, 50, 200, 30), MatchPassword, '*');
GUI.Label(new Rect(300, 90, 130, 30), "Match Max Players");
string maxuser = GUI.TextField(new Rect(400, 90, 200, 30), MatchMaxPlayers.ToString());
MatchMaxPlayers = Interpolator.Parse(maxuser);
MatchMaxPlayers = Mathf.Clamp(MatchMaxPlayers, 8, 32);
}
private void Menu_Lobby()
{
}
}
Could someone please take the time to rewrite the script so that it functions the same, but there are no compile errors?
Answer by robertbu · May 19, 2013 at 02:42 AM
Whenever you see "cannot convert 'object'", look to see what variable you have not declared, or some sort of issue with your declaration. In this case, you declare the variable on line 3 as:
public int MaxmatchPlayers = 32;
But your actual use (and I'm assuming this is the variable you wanted to use) is:
MatchMaxPlayers = Mathf.Clamp(MatchMaxPlayers, 8, 32);
Note the difference in the two names.
Answer by S3dition · May 19, 2013 at 03:26 AM
MaxMatchPlayers is mispelled on declaration (at the top)
GUI.TextField has too many or too few parameters in the overload
GUI.TextField is not a string
Mathf has too many or too few parameters in the overload
You can't use a GameObject as a float.
Look at the rest of the overload error to see what the function accepts and how many arguments you're passing.
Your answer
![](https://koobas.hobune.stream/wayback/20220613102519im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
Multiple Cars not working 1 Answer
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
multi scripts 1 action the same in each. C# 0 Answers
How to make a menu like ironpants 0 Answers