IN my game I put public InputField Userinput and the tutorial i was watching showed me I have to drag the inputfield into the user input but I can do that I even tried adding Public class but that game me errors like {excepted. What should I do?
At first you could share some more information about it!
Screenshots, your code, …
public class GameLogic : MonoBehaviour
{
public class Inputfield
public int randomNum;
// Start is called before the first frame update
void Start()
{
randomNum = 10;
}
// Update is called once per frame
void Update()
{
}
public void OnButtonClick()
{
Debug.Log(“hi”);
Debug.Log(“the random number is” + randomNum);
}
}
This is my code and I have 2 { expected errors and I cant drag the input field into my user input
public class InputField is not the correct way to declare a variable. You are following a tutorial. What did the tutorial tell you to type?
Chances are if you couldn’t connect the InputField in the inspector, you either had compiler errors or you were trying to use maybe the TextMeshPro InputField and not the basic InputField.
I was using the text mesh pro input field. And the tutorial told me to write public inputfield UserInput But because that didn’t work I added class to it but it still didn’t work. I also had to put using Unity.UI. along with that I have a new error that says The modifier public must precede the member type and name.
You can’t just add class to something and have it work. You have to understand what class even means. Go back and redo the script exactly as they did in the tutorial. The only difference is you either have to use a regular InputField in your scene or you use
public TMP_InputField userInput;
as your variable type.
Remember is add using TMPro; at the top of your script as well.
I do feel like maybe a beginner course in c# might help you a lot more right now though.
Putting TMP_ before the Inputfield just gives me a error. and I am using a begginer tutorial but it did not use the TMP.
And did you add the right using statement?
If you want to match the tutorial, than you need to use the same regular old inputfield. Which I already told you to do.