Apr 7, 2016 02:50 PM
(This post was last modified: Apr 7, 2016 02:53 PM by Yurt.)
So I'm messing around trying to create a small game and I've gotten stuck on something very annoying... I've made a SUPER messy script that will allow you to enter your username and then it'll be displayed.. However, I can't figure out how to deselect the textfield after I press enter/return
(I don't want to click outside the textbox with my mouse)
It just creates another line (Which should definitely NOT happen)
I've went through the first 2 pages of google for an answer and NOTHING is working for me......
So someone please help me out so if I press enter it deselects the text field and loads the next level..
(Bonus points if the textfield is automatically activated on start)
(I don't want to click outside the textbox with my mouse)
It just creates another line (Which should definitely NOT happen)
I've went through the first 2 pages of google for an answer and NOTHING is working for me......
So someone please help me out so if I press enter it deselects the text field and loads the next level..
(Bonus points if the textfield is automatically activated on start)
Code
using UnityEngine;
using System.Collections;
public class Username : MonoBehaviour {
public static string name;
public string stringToEdit = "";
void OnGUI() {
GUIStyle myCustomStyle = new GUIStyle ();
GUI.skin.textArea.normal.background = null;
GUI.skin.textArea.active.background = null;
GUI.skin.textArea.onHover.background = null;
GUI.skin.textArea.hover.background = null;
GUI.skin.textArea.onFocused.background = null;
GUI.skin.textArea.focused.background = null;
GUI.skin.textArea.normal.textColor = Color.white;
stringToEdit = GUI.TextField(new Rect(10, 10, 200, 20), stringToEdit, 9, myCustomStyle);
}
void Update()
{
Finished ();
}
void Finished()
{
if (Input.GetKeyDown ("return"))
{
name = stringToEdit;
Application.LoadLevel(1);
}
}
}

