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));
    GUILayout.BeginHorizontal(GUI.skin.box);

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

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

    {

        GUILayout.Label(items[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.EndScrollView();

    GUILayout.EndHorizontal();
    GUILayout.EndArea ();
}
	
	
}

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

  • wholesale nfl jerseys
  • wholesale nfl jerseys china
  • wholesale sports jerseys