Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Sefean · Oct 28, 2016 at 10:50 AM · scenescene-changescene load

Create and build a scene from the code?

Hello, does anybody know if there's a way of creating and building (buttons, cubes, etc.) a scene from the code?

The idea is to have a scene that can change depending on the level you are, for example, at level 1 it would have 4 buttons that the player has to press, and at level 2 it would have 8 buttons. Can you change that scene by code? Or should I create a scene fo every level?

Thanks in advance.

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by tanoshimi · Oct 28, 2016 at 10:54 AM

Yes, of course. Basically:

 int numButtons, levelNum;
 if(levelNum == 1) { numButtons = 4;}
 else if(levelNum == 2) { numButtons = 8;}
 for(int i=0; i<numButtons; i++) { Instantiate(buttonPrefab, Vector3.zero, Quaternion.identity); }

You might want to look through https://docs.unity3d.com/ScriptReference/.

Comment
Add comment · Show 8 · 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 Sefean · Nov 04, 2016 at 10:42 AM 0
Share

Thanks, but that's for an already created scene. I'm asking to creating a new one. So I have a scene with X buttons, and I want to create a NEW scene with Y buttons.

avatar image Zodiarc Sefean · Nov 04, 2016 at 10:45 AM 0
Share

You cannot create a completely different scene(file) during runtime. You always have to have one existing, but you can populate it procedurally.

avatar image Sefean Zodiarc · Nov 04, 2016 at 10:53 AM 0
Share

Ok, so then the best option would be to have an empty scene (or maybe having the background wich is gonna be the same for all the scenes) and adding the objects by code, right?

Show more comments
Show more comments
avatar image tanoshimi Sefean · Nov 04, 2016 at 10:48 AM 0
Share

You can't create new scenes at runtime. But your project can have a single empty scene whose hierarchy is populated at runtime.

avatar image Sefean tanoshimi · Nov 04, 2016 at 10:56 AM 0
Share

I've just found this:

https://docs.unity3d.com/550/Documentation/ScriptReference/Scene$$anonymous$$anagement.Scene$$anonymous$$anager.CreateScene.html

Shouldn't that work? I'll try it when I get home, but have you used it?

Show more comments

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Multiple scenes 2 Answers

Unity Scene loading problem (slow loading until it freezes) 0 Answers

Is there any ideas to load Unity scene asynchronously? 1 Answer

Most efficient way to transition between scenes? 1 Answer

Scene loading delay after upgrade 4.6 to 5. 0 Answers


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