Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by CeeCee · Sep 16, 2013 at 07:48 PM · buttonobject

How to add objects to a scene via button click

I'd like to know how to use a button click to bring objects to the scene. Should I create the objects in a separate scene, say scene 1? Create a button in scene 2 and then when the button is clicked the object/s appear.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
3

Answer by mirkobon · Sep 16, 2013 at 08:18 PM

Make a prefab, to do this drag the object in your hierachy to your assets. And as scripting:

 var object1 : prefab
 var myposition : GameObject;
 
 function OnGUI ()
 {
         if (GUI.Button(Rect(10,10,100,100),"Button name"))
            {
                  Instantiate(object1, myposition.transform.position, myposition.transform.rotation)
             }
 }

And in the inspector assing the variables

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image CeeCee · Sep 16, 2013 at 08:24 PM 0
Share

Thanks $$anonymous$$irkobon! I'd just been looking at the tutorials on youtube for prefabs but they were more to do with spawning objects for shooter games etc. I'll try this out.

avatar image leonardosetiadi · Dec 10, 2015 at 11:16 AM 0
Share

theres an error on var object1 : prefab var myposition : GameObject;

avatar image leonardosetiadi · Dec 10, 2015 at 11:19 AM 0
Share

there's an error on
var object1 : prefab var myposition : GameObject;

need help!

avatar image BackslashOllie leonardosetiadi · Dec 10, 2015 at 11:30 AM 0
Share

Add a semicolon to the end of the prefab declaration. $$anonymous$$G. var object1 : prefab;

avatar image
1

Answer by dannyskim · Sep 16, 2013 at 08:09 PM

Technically, you could do that I guess... But what you're really wanting is to Instantiate an object:

http://docs.unity3d.com/Documentation/ScriptReference/Object.Instantiate.html

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image CeeCee · Sep 16, 2013 at 08:14 PM 0
Share

Thanks Danny, I'll give that a go!

avatar image mirkobon CeeCee · Sep 16, 2013 at 08:19 PM 0
Share

Next time use comments :)

avatar image mirkobon · Sep 16, 2013 at 08:18 PM 0
Share

Lol was typing at the same time

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

19 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Placing scene object in inspector as a varable and load with button in game 1 Answer

How can I bind a custom object or variable to an UI button? 2 Answers

On mouse down switch on / off 2 Answers

increase size of object when button pressed 0 Answers

CS0029 convert type 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges