Creating a List in Unity using C# for mobile devices

I found this script to make a list in a Stack Over Flow forum board but I added a few things to it including responding to clicks and couple other insertions. Plus if you found this post before the SOF then I saved you some time.

List Unity3d

Here is the code:


using UnityEngine;
using System.Collections.Generic;

public class test : MonoBehaviour {

List items;
Vector2 scrollVector;

void OnGUI()

		items = new List();
		items.Add("Game 1");
		items.Add ("Game 2");
		items.Add ("Game 3");
		items.Add ("Game 4");
	GUILayout.BeginArea (new Rect (20,80, 400, 300));

    scrollVector = GUILayout.BeginScrollView(scrollVector);
	GUILayout.Label("Category Selected" , GUILayout.Width(200), GUILayout.Height(30));

    for (int i = 0; i < items.Count; i++)


        if (GUILayoutUtility.GetLastRect().Contains(Event.current.mousePosition) && 
				(Input.touchCount > 0 &&  Input.GetTouch(0).phase == TouchPhase.Began))

				// Do what you need to do here
				print(items[i]); //You will not see this from your phone. Just example



    GUILayout.EndArea ();

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Graveyard Database Logo

Has everything you want to know about grave yards. Plus has many celebrites and world leaders graves. Pssst it is my other site

Google + Profile
Check out Android Photo Mapping, its a app/site I been working on
Fabulou wholesale Petr Mrazek jersey is back. Best choice to get the wholesale Petr Mrazek jersey is suitable for all style of people.