- Home /
Spawn Object On Gui (button Press)
So im trying to figure out when I left click my Gui button that it will spawn the object the Gui tells it to spawn. a Script that "When it recives a left button click" it runs "Spawn Object (Name)
I have my own system put in of Object ID List,
var House : GameObject;
function Update() {
if(Input.GetButtonUp("Jump"))
Instantiate(House, transform.position, transform.rotation);
}
Please help thank you :)
Answer by Glinny · Aug 10, 2012 at 11:53 AM
Try this on for size; var House : GameObject function Update(){ if(Input.GetButtonup("KeyCode.Space)){ Instantiate(House,transform.position,transform.rotation.
I think this'll work but don't have Unity here to try it with
Answer by NiklasBorglund · Aug 10, 2012 at 11:53 AM
I'm not sure I understand exactly what you mean, but If you want an object to spawn whenever you left click anywhere on the screen - you could just do a check id the left mouse button is clicked.
function Update()
{
if(Input.GetMouseButtonDown(0))
{
Instantiate(House, transform.position, transform.rotation);
}
}
Otherwise, If you want to spawn an object when you click on something(like a button), it's basically the same procedure - you just put the code elsewhere. You can find some good documentation of the Unity GUI-system here.
In the code you have there, If you haven't changed any values in the Input Manager and initialized everything correctly - an object would spawn if you press space.
Your answer
![](https://koobas.hobune.stream/wayback/20220613075442im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Counter of clicks after gui.button pressed 2 Answers
How do I create a Gmod item spawn menu in unity? 0 Answers
GUI Button for Android 1 Answer
GUI Button to create another GUI 1 Answer
i need to destroy prefab clones 1 Answer