Hello all, I'm making an horror game. I'd like an script on a car that if you press "E" an text appear. And after press "E "again the text dissapears.. Some1 can help me? Regards, Melchet
Maybe try a script with something like this: Code (CSharp): bool textShowing = false; void Update () { if (Input.GetKeyDown (KeyCode.E)) textShowing = !textShowing; } void OnGUI () { if (!textShowing) return; GUIStyle style = new GUIStyle (); style.fontSize = 130; style.normal.textColor = Color.white; GUI.Label (new Rect (10, 10, 100, 20), "Hello World!", style); }
I think there are two issues. One issue is that I think it is a problem to put a space in the name of a Unity script. So, you should change “car text” to “cartext” or something without a space. Also, here is some code that assumes you have named your script “cartext”: Code (CSharp): using UnityEngine; using System.Collections; public class cartext : MonoBehaviour { bool textShowing = false; void Update () { if (Input.GetKeyDown (KeyCode.E)) textShowing = !textShowing; } void OnGUI () { if (!textShowing) return; GUIStyle style = new GUIStyle (); style.fontSize = 130; style.normal.textColor = Color.white; GUI.Label (new Rect (10, 10, 100, 20), "Hello World!", style); } } The code I gave you before was a snippet and wasn’t intended to occupy the whole file.
Hello boolfone, the script worked. But now I got the problem if I press the 'E ' key the text shows anywhere.. I have putted the script on the car itself
You can move the text by setting the first two parameters to the Rect constructor in this line: GUI.Label (new Rect (10, 10, 100, 20), "Hello World!", style); Also, if you want, you can use this script: Code (CSharp): using UnityEngine; using System.Collections; public class cartext : MonoBehaviour { bool textShowing = false; public float x; public float y; void Update () { if (Input.GetKeyDown (KeyCode.E)) textShowing = !textShowing; } void OnGUI () { if (!textShowing) return; GUIStyle style = new GUIStyle (); style.fontSize = 130; style.normal.textColor = Color.white; GUI.Label (new Rect (x, y, 100, 20), "Hello World!", style); } } Then you can adjust the x and y position for the text like so:
Thx for the video. but that isn't actualy the answer on my question. the problem is the text what belong with the car gonna show up everywhere when I press the 'E"button. It only needs to be showing at the car.
Let me explain better, This picture is the good position when I pressing 'E'. Now the girl stances to the car This picture is the bad one, here I press 'E' too but without the car. I need the text only shown up at the car as the picture above.