Newbie Question

Hey guys, this may sound like a stupid question but I’m having trouble using class functions.

For example, I’m trying to use the GUI.Textfield function, however when looking at the manual I read I need to include a class like this:

public string stringToEdit = "Hello World";
    void OnGUI() {
        stringToEdit = GUI.TextField(new Rect(10, 100, 200, 20), stringToEdit, 25);
	}

Once I’ve defined it how can I utilise it or call it.

On the update() function I wanted to be able to activate it on Input.GetMouseButtonDown and call GUI.Textfield.

Any light on this would help.

I believe the GUI is sensitive to all input automatically. Can you not just use

if(stringToEdit)
///do stuff

so if you input on the textField, things will happen.

I’m just wanting some text to appear on the screen as I’m making a 2D still image game. But of course I need certain text to appear when clicking certain positions in X,Y,Z. Any ideas?

Huh? You can’t convert a string to a bool. I’m not really sure what evaluation that would do anyway.

OnGUI is called automatically for every MonoBehaviour in the scene if it contains such a method. You can check for mouse click input in Update() which is also automatically called. Beyond that your question isn’t really clear.

I’m sorry if it wasn’t clear. But basically what I’m trying to do is have some text appear on the screen at a position I set. When clicking on a certain part of the screen. I thought this may of been the function I was looking for. I’ll look for something else that may work for what I need. Thanks

Also rather then just creating a text field on the screen then just coding in what to write in the box when clicking certain things. I was thinking about having the code create the text field, position at the coordinates I set and write what I want inside. Make sense?

using UnityEngine;
using System.Collections;

public class WindowShow : MonoBehaviour {
	
	public string stringToEdit = "";
    void OnGUI() {
        stringToEdit = GUI.TextArea(new Rect(10, 10, 200, 100), stringToEdit, 200);
    }
	
	// Use this for initialization
	void Start () 
	{
	
	}
	
	// Update is called once per frame
	void Update ()
	{
		if(Input.GetMouseButtonUp(0))
		{
			stringToEdit="Hi";
			
		}
	}
	
	
	
}

I guess like this, Not sure if it’s the best way of going about it. But obviously now I’d include different things to write depending on what part of the screen you click on.