Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 DubstepDragon · Mar 31, 2013 at 08:57 PM · randomproceduralgeneration

Procedural Generation...

I have an array of gameobjects called "Rooms". I also have an int called "AllRooms". In my start method, I set "AllRooms" to equal "Rooms.Length". Now I am looking for a possible way on how to instantiate the rooms and destroy them after 10 seconds of existence. Do I have to use Empty GameObjects to define the next room's location? I am new to procedural generation, and this is my first attempt on working on an infinite runner game. Also, I was thinking of using the Random.Range term to randomly generate the rooms, as this is one of my main mechanics.

Please consider the fact that all my work is in C#.

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

2 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by dorpeleg · Mar 31, 2013 at 09:22 PM

Place this script on all of your rooms:

 using UnityEngine;
 using System.Collections;
 
 public class KillOnTime : MonoBehaviour {
     
     public float OnTime;
     
     void Awake () {
         Destroy(gameObject, OnTime);
     }
 
     // Use this for initialization
     void Start () {
     
     }
     
     // Update is called once per frame
     void Update () {
     
     }
 }

Then use the inspector to chose the time before destroying.

If you look at the Instantiate function, you can see that it is possible to give a location (no need for an empty gameobject)

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 DubstepDragon · Apr 01, 2013 at 11:02 AM 0
Share

Thank you very much! Now I understand it all - it is really a simple concept...

avatar image DubstepDragon · Apr 01, 2013 at 11:23 AM 0
Share

Hmmmm... I always use WaitForSeconds in my scripts...

avatar image dorpeleg · Apr 01, 2013 at 03:23 PM 0
Share

The problem with WaitForSeconds is that it stops the script completely for the amount of seconds.

So it might not always be the best way to wait for something.

avatar image
0

Answer by Hotshot10101 · Apr 02, 2013 at 01:05 AM

There is another method as well. You said that you are creating the rooms somewhere as well. I assume you are using Instantiate. If not then the above is the best way.

If you are using Instantiate then you can do something like the following at the place you are creating the rooms:

 GameObject gameObject = Instantiate (roomBaseObject, postition, rotation);
 Destroy (gameObject, 10f);
 

The 10f in the Destroy call is the time to wait until you want to destroy it.

Comment
Add comment · 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

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

12 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

Related Questions

Procedurally Generated Room System... 1 Answer

how to procedurally generate submarines with random events on the sub? 0 Answers

Procedural Random Walk Dungeon Generator? 2 Answers

Random Spawning 1 Answer

Randomly Generated Levels 3 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