Unity GUI Combobox or Dropdown

I'm using C# Script. Create C# Script named Dropdown. This method is when the button clicked, another button show.

using UnityEngine;
using System.Collections;

public class Dropdown : MonoBehaviour {
 public string[] items;
 public Rect Box;
 public string slectedItem = "";
 bool editing = false;
 void OnGUI(){
  if (GUI.Button(Box, slectedItem)){
   editing = true;
  if (editing){
   for (int x = 0; x < items.Length; x++){
    if (GUI.Button(new Rect(Box.x, (Box.height * x) + Box.y + Box.height, Box.width, Box.height), items[x])){
     slectedItem = items[x];
     editing = false;

Attach the script in game object main camera then setting value.
 Play and see the Result. When click the Number button show other button.
The source of this tutorial

No comments:

Post a Comment