Quantcast
Channel: Questions in topic: "selectiongrid"
Viewing all articles
Browse latest Browse all 94

Selectiongrid too many action calls...

$
0
0
Hey there, I have a number of buttons built from a selection grid. What I want to do is when you click a button, it makes just one call/action. At present, it keeps calling and generating multiple instantiations of the object as the button is active I think. Is there a way so it just calls once? Here's my code so far... using UnityEngine; using System.Collections; public class SelectionGridTest : MonoBehaviour { public GUISkin leftnav; public int selGridInt = 0; public string[] selStrings = new string[] {"Grid 1", "Grid 2", "Grid 3", "Grid 4", "Grid 5", "Grid 6", "Grid 7", "Grid 8"}; //Instansiate object references public GameObject TheObject; void OnGUI() { GUI.skin = leftnav; GUI.Box(new Rect(-90,14,100,320),""); selGridInt = GUI.SelectionGrid(new Rect(40, 40, 70, 800), selGridInt, selStrings, 1); if (selGridInt == 0) { // execute code for loading Object1 GameObject objTheObject = (GameObject)Instantiate(TheObject, new Vector3(0,0,0), transform.rotation); } else if (selGridInt == 1) { // execute code for loading level //////Application.LoadLevel(1); } else if (selGridInt == 2) { // execute code for destroying tag Destroy (GameObject.FindWithTag("TheObject")); } } }

Viewing all articles
Browse latest Browse all 94

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>