I’m a beginner in unity and I want to get a user’s name after my game ends, so I can save his score. To do this, I found out you use GUILayout.TextField(). I looked it up and made a C# script using it but for some kind of reason it gives me a compiler error. Here is the script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class NameGUI : MonoBehaviour {
public string PlayerName = "Name Here";
void OnGUI(){
PlayerName = GUILayout.TextField (new Rect(0, 0, 200, 20), PlayerName);
}
}
And it gives me this error message:
*The best overloaded method match for ‘UnityEngine.GUILayout.TextField(string, params UnityEngine.GUILayoutOption)’ has some invalid arguments
Argument 1: Cannot convert from ‘UnityEngine.Rect to string’
Argument 2: Cannot convert from ‘string’ to ‘UnityEngine.GUILayoutOption’*
I would really appreciate your help.
If you have any questions, you can simply ask.