I would like to have a button, that when I press it, it instantiates a prefab at a certain location. For me that sounded s...

posted to: Interactive Buttons
I would like to have a button, that when I press it, it instantiates a prefab at a certain location. For me that sounded super easy, if I was to use a key I could just do if getbuttondown "R", then instantiate (Object,Vector3,Rotation) etc. etc. etc. But with buttons, it only calls functions certain functions, and public voids are not one of them. Any advice on how to do that? Ironically all YouTube tutorials are so focused on SceneManager, that no one shares how to use anything else but Int based buttons. Thanks!
  • Kyle Shaffer(kyleisdank) replied
    Wait no what am I saying I'm a dumbass. Why is it I always ask questions and then RIGHT after asking it I figure it out. Okay so just make a public void like lets say public void CreateWeapon (Int scene), (because you guys did Int Scene and im not creative at all), then underneath just referance your other function, so I called that SpawnWeapon();. Now that I through the int in there, I can refrence it from the button and walaaaa. Thanks guys your videos are the best on the internet, even if they don't specifically apply to the situation, you provide so much insight it allows us to explore more objects. Great stuff!
  • Jonathan Gonzalez(jgonzalez) replied

    That almost always happens when I ask a question so I know the feeling. A couple things I wanted to mention. If you’re not using the “int scene” then leave it out. It was added because that function could be used with any button then we could just change the number for a specific level. So one function with three buttons that load 3 different levels.

    Also you could just make your Instantiation function, SpawnWeapon(), public and just use that directly with your button. That function will only be called when the button is pressed. Just make sure it’s not included within the Update function, otherwise it’ll automatically instantiate objects.