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 SamOf2 · Jan 12, 2015 at 07:17 AM · spawningcube

Need Help Spawning Cubes Constantly In Front Of Player

So in my game there is a first person controller that falls inside 4 walls that lock it in(as if you were falling inside an empty skyscraper) and i want there to be cubes that generate at random x and z positions but staying inside the walls, before the player reaches them(so generating at a specific y aswell) i would like this to be constant and for the cubes to be destroyed after the controller has passed them.

i have kind of tried this already so but all i managed was a bunch of cubes generating every second in the same position, here is my code:

using UnityEngine; using System.Collections;

 public class Generator : MonoBehaviour {
 
         public GameObject cube;
         public int numberOfCubes;
         public int min, max;
         public float Time = 3f;
 
         // Use this for initialization
     void Start () {
                 InvokeRepeating ("PlaceCubes", Time, Time);
     }
     
     // Update is called once per frame
     void PlaceCubes () {
     
     
                 for (int i = 0; i < numberOfCubes; i++) {
 
                         Instantiate (cube,GeneratedPosition(),Quaternion.identity);
 
                 }
         
         }
         Vector3 GeneratedPosition()
         {
                 int x,y,z;
                 x = Random.Range(min,max);
                 y = Random.Range(min,max);
                 z = Random.Range(min,max);
                 return new Vector3(x,y,z);
         }
 
 }
 

i would also like to mention that i am a bit of a noob!

so if you could help me and tell me what i need to , be it creating a new script that would be great thanks!

Comment
Add comment · Show 1
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 SamOf2 · Jan 14, 2015 at 04:40 PM 0
Share

30 -30 but the only difference it makes is the size of the ware where the cubes are allowed to spawn

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by LT23Live · Jan 12, 2015 at 08:07 AM

I would like a little bit more details. How quickly do you want the cubes to spawn.

A small tip The cubes you want should be prefabs with a destroyer script set to them. The script should have OnTriggerEnter used. Then destroy the gameobject.

Comment
Add comment · Show 1 · 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 SamOf2 · Jan 12, 2015 at 05:23 PM 0
Share

Ok i would like to cubes to spawn every 5 seconds say, similar to a game like temple run, and i would like the cubes to be destroyed once the first person controller has passed them. I presume the rest you understand, thank you

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

2 People are following this question.

avatar image avatar image

Related Questions

How can i destroy cubes that is randomly generated when i have passed them? 1 Answer

How to make an object spawn in different positions? 2 Answers

Spawning won't work 1 Answer

Spawning Cube on empty gameobject 1 Answer

cube spawn next to another cube in the same row 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