- Home /
Dropdown box in script.
So here's what I have in mind. I'd like to make a script that allows me to choose the spawn location of the gameObject that I have the script attached to. I would have 9 defined spawn points. My original thought was to make a an enum or something that holds the spawn points and then via a dropdown box or something of that nature, I'd like to be able to choose the spawn location. Does anyone have any suggestions on a good way to do this? Thanks in advance!
$$anonymous$$ake a button
When you click the button, show more buttons underneath it
when you click the button again, and if the option buttons are shown, hide them.
If an option button is clicked, spawn in that location.
Thanks for your comment @AcE_fLoOdEr. I may not have been clear enough about what I'm wanting to accomplish. I want the dropdown list to be available in the editor, on the script. Then I can attach the script to an object and set it's spawn location. Any ideas?
Why not just use a public Vector3 (or Vector2 for 2D) variable to define the position (which you can freely change in the inspector)?
Or if you want to have predefined presets, you could use a Vector3 array, and an integer to define which one to use:
public int positionToUse = 0; //Which position to use
public Vector3[] positions = {
new Vector3 (1, 0, 0), //This one would be 0
new Vector3 (1, 0, 1) //This one would be 1
// etc
}
...
//Access the position something like:
myActualSpawnPosition = positions[positionToUse];
Not exactly a dropdown menu, but I'm assu$$anonymous$$g your goal is simply quicker access.
Answer by DocMcShot · Jan 28, 2015 at 04:39 AM
I figured it out so I thought I post to help someone else out. Here's what I did to get a selectable drop down on the script in the editor. It works perfectly!
public enum AnimationLocation {upperLeft = 1, upperMiddle, upperRight,
middleLeft, middleMiddle, middleRight,
lowerLeft, lowerMiddle, lowerRight};
public AnimationLocation animPlayArea;
Your answer
Follow this Question
Related Questions
affecting only one Prefab in Code. (script) 1 Answer
Selecting Random Object and Setting Variable to True 2 Answers
Select object in another scene 1 Answer
Draw Rectangle 0 Answers
Change shape of object if selected? 1 Answer