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 randomuser · Oct 25, 2012 at 01:30 AM · c#transformprefabsspawning

Spawning objects around a point

Hello! I am somewhat new to scripting in Unity and have no idea of ways to do this. I want to spawn a cube made of smaller cubes around 0,0,0. However, the size of the big cube spawned will differ based on the number of little cubes used building it, but still needed to remain centered at 0,0,0. Is their any way to move a group of objects to center them at 0,0,0 or is their another way to do this. Thanks.

Comment
Add comment · Show 5
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 randomuser · Oct 25, 2012 at 12:56 AM 0
Share

I do know how to spawn objects, I just don't know how to spawn a bunch of them around a point

avatar image liszto · Oct 25, 2012 at 05:36 AM 0
Share

I don't really understand but you define randomly on start the size of the cubes (the littles) which is the same for all right ? Then you want define the number of cube (little) on a side and then you build it like that ?

OR

You define the size of a side, then you divide it by the size of a little cube (size of little is still choose randomly) ?

It's just to know how to explain how to do that :)

And I think this is something that can really help you here : http://docs.unity3d.com/Documentation/$$anonymous$$anual/InstantiatingPrefabs.html

avatar image chesterr400 · Oct 25, 2012 at 11:38 AM 0
Share

About moving a group of objects, try to make the other objects a child of an object, that way, when you try to move the parent object, all of them will follow.

avatar image randomuser · Oct 25, 2012 at 11:38 PM 0
Share

so you are saying break the big cube of the size chosen into a bunch of little cubes? Is there even a way to do that?

avatar image chesterr400 · Oct 26, 2012 at 02:36 AM 0
Share

hmm, you could create a small cube, duplicate it and use them to create a bigger one. as you duplicate that small cube, make the duplicated cube a child of the original, that way, when you move the original cube, every cube will follows.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by chesterr400 · Oct 25, 2012 at 06:34 AM

Hi!

First create that "cube made of smaller cubes" and put it into a prefab.

Next, copy the code below (this is a code I found on unity answers too and just modified it, credits to the owner of the code and I forgot who he/she is) and paste it into a new JS script.

Then, create an empty game object and drag the JS script in it.

Select the prefab that you've created and add a rigidbody on it.

Once the prefab has a rigidbody, click the empty game object with the script, apply the prefab that you've created to that script.

Make sure that the "cube made of smaller cubes" you've made is positioned at (0,0,0)

 var timer : float = 0.0;
 var spawning : boolean = false;
 var prefab : Rigidbody;
 var spawn1 : Transform;
 
   
 function Update () {
  //check if spawning at the moment, if not add to timer
  Debug.Log(Application.loadedLevelName);
  if(!spawning){
   timer += Time.deltaTime;
  }
  //when timer reaches 2 seconds, call Spawn function
  if(timer >= 2){
   Spawn();
  }
 }
  
 function Spawn(){
  //set spawning to true, to stop timer counting in the Update function
  spawning = true;
  //reset the timer to 0 so process can start over
  timer = 0;
  
  //select a random number, inside a maths function absolute command to ensure it is a whole number
  var randomPick : int = Mathf.Abs(Random.Range(1,3));
  
  //create a location 'Transform' type variable to store one of 3 possible locations declared at top of script
  var location : Transform;
  var thingToMake : Rigidbody;
  //check what randomPick is, and select one of the 3 locations, based on that number
  if(randomPick == 1){
   location = spawn1;
  
   Debug.Log("Chose pos 1");
  thingToMake = Instantiate(prefab, location.position, location.rotation);
   
  
  }
  
  
  //halt script for 1 second before returning to the start of the process
  yield WaitForSeconds(1);
  //set spawning back to false so timer may start again
  spawning = false;
 }
Comment
Add comment · Show 2 · 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 liszto · Oct 25, 2012 at 06:46 AM 0
Share

I don't think it's what he needs or wants...

And I don't think give him a solution like that is the good thing to do

avatar image chesterr400 · Oct 25, 2012 at 11:34 AM 0
Share

I'm sorry, thanks for the criticism, I'll try to make a better way of answering ^_^

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

11 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

Related Questions

Custom level creator for players 1 Answer

Distribute terrain in zones 3 Answers

Multiple Cars not working 1 Answer

C# Timer and Spawning Prefabs - 2d Sidescroller 1 Answer

how to move an object to a lacation slowly? 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