Page 1 of 1

Kan man lave et GUI.Textfield med 2 eller 3 linjer tekst?

Posted: 14 Apr 2012, 08:42
by organicoder
Unitys forum er nede, så nu forsøger jeg mig med at spørge her :-)

Er det muligt at lave et tekstfelt, brugeren kan redigere med mere end en linje?

Code: Select all

using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class CreateGoal : MonoBehaviour {
	
	//int PrintLabelYPosition = 200;
	bool showList = false;
		
	public List<string> stringList = new List<string>();
       public string stringToEdit = "Write which goal you completed here";
	
    void OnGUI() 
	{
		stringToEdit = GUI.TextField(new Rect(10, 130, 220, 42), stringToEdit, 100);
		
		//Button for adding a new string to the list
		if (GUI.Button(new Rect(10, 180, 210, 21), "Complete goal"))
		{
			stringList.Add(stringToEdit);
		}
		
		//Button for printing out the list to the console
		//if (GUI.Button(new Rect(10, 210, 210, 21), "Debug List to console"))
		//{
		//	DebugList();	
		//}
		
		//Button for printing out the strings in the list to the screen	
		if (GUI.Button(new Rect(10, 240, 210, 21), "Print list to screen"))
		{
			     showList = !showList;
		}

		if (showList == true)
			PrintList();
    }
	
	//Function that prints out the strings in the list to the console
	void DebugList()
	{
		foreach(string s in stringList)
		{
			Debug.Log(s);	
		}
	}
		
		//Function that prints out the strings in the list to the screen
	void PrintList()
	{
		int PrintLabelYPosition = 260;
        foreach(string s in stringList)
		{
			GUI.Label(new Rect(10, PrintLabelYPosition, 500, 20), s);    

             PrintLabelYPosition = PrintLabelYPosition + 20;

        }
	}
	
}

Re: Kan man lave et GUI.Textfield med 2 eller 3 linjer tekst

Posted: 14 Apr 2012, 10:55
by ThomasLund

Re: Kan man lave et GUI.Textfield med 2 eller 3 linjer tekst

Posted: 14 Apr 2012, 11:03
by organicoder
Fantastisk! Mange tak. Det er ikke sidste gang, jeg spørger efter hjælp her :-)