- Home /
Naming a gui?
Hello, I can't seem to understand how you would be able to edit for example a GUI text with a button. For example if I want to make a textbox and have a button make the text += 1 every time I click it how would I go about doing this? I have read some basic tutorials on GUI's, however I don't understand how you get the name to change the text of for example that textbox in c#.
Answer by robertbu · May 14, 2014 at 09:07 PM
It it hard to understand exactly what you are looking for. Attach this to an empty game object and hit run. Note you should play with the various example scripts for the GUI class in the reference manual. Take a look at the entries for the individual methods, then copy, paste, and play with the scripts.
using UnityEngine;
using System.Collections;
public class Example : MonoBehaviour {
int score = 0;
void OnGUI() {
if (GUI.Button (new Rect(25,25,75,35), "Add Point")) {
score++;
}
GUI.Label (new Rect(50,75,75,35), score.ToString ());
}
}
Ah, I realize I was a bit vague with my description, but right after looking at that code bit you posted I realized what I was having trouble with. Thanks
Your answer
Follow this Question
Related Questions
Point counter = 0 if change level ... HOW ? 2 Answers
How to cycle weapons and parent it? 1 Answer
Missing prefabs and missing prefabs(dummy). 0 Answers
Generic List.Count always gives 0 2 Answers
How to make a Grenade in C# and apply different damages 0 Answers