- Home /
Add game building items to dropdown list?
I am still a beginner with 3d Unity, and have accomplished a main menu, character selection scene, choose faction scene, and have made my main map. I got several different types of characters, and building structures etc.
What I am trying to learn: How to get a list of my building structures for the player to select houses, walls, tables etc. to put that item into the game wherever the player may choose.
(My purpose in what I am aiming for) For most games a player will press "B" to open up a menu that the player can select "Buildings", and is presented with a list of building types with pictures of each building. The player then can select a building of choice, and it is put into the game where the player can choose where to place the building at.
I am wanting to do this through UI canvas > dropdown list (called building) > select building (small, medium, large) > New sub list pops up with the pictures of buildings to choose from for that category. Then the player can select the building, and place it wherever they want in there game.
Where I am stuck at: I am stuck on how to make a building type show up in the list with a picture of it, and place it in the scene.
I have spent a couple of hours trying to look up Character Object List, but to no avail.
What training, videos (that I have missed) do I need to look at to better understand how to do this process?
What I have so far: In the main game I have the Canvas > Dropdown list name "Buildings" > option1 small > option2 medium > option3 large.
Another canvas for each option (small, medium, large) to populate the list of the specific buildings.
Thank you for your time and effort have a great day!
Answer by sentar · Mar 01, 2017 at 07:24 AM
Update
With having complication with Dropdown list, I decided to use the standard Button, and create another canvas for small, medium, large building selection, after selecting small, it opens up another canvas that should have the list of smaller buildings inside it. I just have to figure out how to make the buildings show up in that canvas (if it is possible).
The structure:
1st Canvas is Button "Building" > 2nd Canvas is Button "Small" is selected by player > 3rd Canvas, (list of buildings to populate for player to choose from).
Another Update on my current status:
I was able to understand that a prefab is the building object, and I got the building to come into the scene with adding rigidbody to it and using this code to make it appear. However, I am still learning how to add the prefab into the list on the 3rd Canvas.
Current Script: public GameObject smalllist; GameObject smalllistclone;
// Use this for initialization
void Update () {
if (Input.Get$$anonymous$$eyDown("3"))
{
smalllistclone = Instantiate(smalllist, transform.position, Quaternion.identity) as GameObject;
}
if (Input.Get$$anonymous$$eyDown("4"))
{
Destroy(smalllistclone);
}
}
So now ins$$anonymous$$d of, Input.Get$$anonymous$$eyDown I will continue my pursuit in researching how to make it recognize when I click on "small building" button I created in the 3rd canvas to appear like the script with pressing "3".
Then I will attempt to learn how to do the rotation of the prefab, and allowing player to place the prefab wherever desired.
I changed the if statement to:
public void InsertPress() { if (Input.GetButtonDown("Barrell1")) { smalllistclone = Instantiate(smalllist, transform.position, Quaternion.identity) as GameObject; } } public void UndoPress() { if (Input.GetButtonDown("Undosmallbuilding")) { Destroy(smalllistclone); }
I added this into the button, and got the function to accept the Instert/Undo; however, now I cannot see it appear in the game. I have an instantiator on my character, now will try to learn how to make that instantiator work.
all I had to go is remove the if statement but leave my internal code, and now the button works with putting a building into the game!!
Now I just have to learn how to add a 2d image of the prefab with the button beside it.