Hey guys! Total newbie here.
I want to call the index value of a dropdown selection, but I have no idea how to do that. Any thoughts?
Hey guys! Total newbie here.
I want to call the index value of a dropdown selection, but I have no idea how to do that. Any thoughts?
Solved it! Here’s my code, for anyone looking for an easy solution. Add a script with this code to the Dropdown GameObject and assign it and the specific function (“onHerkunftChoose” in my case) to the dropdown OnValueChanged!
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class HerkunftDropDown : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
public void onHerkunftChoose () {
int chosenInt = GameObject.Find ("HerkunftDropdownMenu").GetComponent<Dropdown>().value;
print (chosenInt);
}
}
Just a question, what was your problem that you had? I want to see if i can use it to solve my own problem.
He needed the index element selected on a dropdown, his solution: int indexElement= GameObject.Find ("HerkunftDropdownMenu").GetComponent<Dropdown>().value;
– amorales
Forgot to mention: Using C#.
– AmeisenfutterTry this out : public var MuzzleFlash : ParticleSystem; var GeneratedPosition; function Start(){ var x=0;var y=0;var z=0; x = Random.Range (0.1, 2.9); y = 10; z = Random.Range (0.1, 1.9); GeneratedPosition = new Vector3 (x, y, z); } function Update(){ if(Input.GetMouseButtonDown(0)) { Instantiate(MuzzleFlash, GeneratedPosition,Quaternion.identity); } }
– efeguclu