- Home /
Problem with clearing a textfield in every scene C#.
So, in a nutshell:
I have two scenes. We'll call them SceneX and SceneY.
In SceneX you see a textfield. You write, let's say, "SCENEY" in it and you can move on to the SceneY.
When you enter SceneY you see yet another textfield. Same as in SceneX. You have to once again write something in it, let's say in this case "SCENEZ" to move on to the next scene. However, when you tap the textfield it shows the text "SCENEY" that we wrote in SceneX. Unless you lock your phone and reopen it the text won't disappear and you are unable to write new text.
It only happens on phone (Android). In Unity game mode everything works perfectly. So what to do? The code is rather simple and presented below
using UnityEngine;
using System.Collections;
using System;
public class Game : MonoBehaviour {
string textToEdit = "";
public GUISkin customSkin;
void OnGUI()
{
GUI.skin = customSkin;
textToEdit = GUI.TextField (new Rect (100, 190, 260, 50), textToEdit, 30);
}
// Use this for initialization
void Start ()
{
}
// Update is called once per frame
void Update ()
{
if (textToEdit == "PASSWORD")
{
Application.LoadLevel ("scenez");
}
}
}
Answer by zharik86 · Nov 15, 2014 at 07:41 AM
For android device try add:
private TouchScreenKeyboard keyboard;
void Start() {
//Use platform dependent
#if UNITY_ANDROID
keyboard = TouchScreenKeyboard.Open("");
keyboard.active = false;
#endif
}
I hope that it will help you.
@L$$anonymous$$$$anonymous$$21 if I helped you, please, mark my answer (below vote button).
Its just a case of having not entered a blank string before the next usage.
Your answer
Follow this Question
Related Questions
GUILayout.TextArea/TextField not working. 1 Answer
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Problem with clearing textfield C#. 0 Answers
Add GUI elements to Scene View? 3 Answers