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

organicoder
Level 1 - Speck of dust
Posts: 11
Joined: 26 Dec 2011, 10:49

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

Unread post by organicoder » 14 Apr 2012, 08:42

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;

        }
	}
	
}

ThomasLund
Level 23 - Spider demon
Posts: 230
Joined: 16 Mar 2011, 18:28
Contact:

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

Unread post by ThomasLund » 14 Apr 2012, 10:55

Full Control
Makers of Smack Boxing, Smack Hockey, Monster Ball, Electrocute, Touch Wars, Tactical Soldier, Frontline Tactics, Space Hulk, Jagged Alliance Flashback, Space Hulk Ascension

organicoder
Level 1 - Speck of dust
Posts: 11
Joined: 26 Dec 2011, 10:49

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

Unread post by organicoder » 14 Apr 2012, 11:03

Fantastisk! Mange tak. Det er ikke sidste gang, jeg spørger efter hjælp her :-)

Post Reply