Place a prefab in game on button click
Hey guys, I am new to unity and I am trying to create a game where the player can spawn in minions from some in-game buttons by clicking them and dragging the minion and placing them into the game world. Kind of like an RTS building placement system.
I followed a tutorial which gave me the desired effect:(https://www.youtube.com/watch?v=OuqThz4Zc9c)
But I found out after completing the tutorial that Unity added an easier way to create buttons on a canvas rather than hard code them like in the tutorial and i would like to migrate the placement system to the new Unity 5 buttons for ease of use, but for the life of me I cant figure it out or find any help online.
Any point in the right direction or explanation would be greatly appreciated!
Sorry if my post is confusing in any way, yours sincerely a very confused individual.
Answer by MitchWardle180 · Jun 02, 2015 at 03:08 PM
Whatever happens when you click the button, create a new public function/void and add the code that you used on your old buttons and when you add your new buttons to the canvas in the inspector scroll down the to onClick function and locate the public function/void you created.
**Hope this is easy to read and understand and the fix should be along those lines^.
i followed that tutorial too.. but i have a problem.. im newbie about scripting.. can you explain it step by step? :(
Answer by JackTheNerd · Nov 19, 2015 at 05:54 AM
Go into the buttons and add a System Event Type Component, then select OnPointerClick and have it execute the function from your script by dragging in the parameters, this is probably the simplest way to do this.
@Bebop980
Your answer
Follow this Question
Related Questions
Adding additional C# scripts after build (Android, iOS) 1 Answer
Problem with TextMesh Pro when running a build of the game - how to get the right text? 0 Answers
entire project lost touch input 0 Answers
I want to highlight the correct answer when wrong one clicked... Help! 1 Answer
Making text appear by pressing a button, only when player is close to the object 1 Answer