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 Concavebark · Oct 09, 2017 at 09:39 PM · instantiateprefabscript.

I'm trying to procedurally generate a couple prefabs for a game i'm making in 3D

I'm trying to figure out how to create a procedurally generated map with 10x10 prefabs, I know that i have to use the Instantiate method but how would i come up with the correct coordinates for the next few prefabs, so that the player never catches up with the edge of the map. I also want to include a random selector for the prefabs that way it's not always the same prefab being created and there is a little bit of "spice" to the world. I've been trying to figure this out for a couple hours and I'm stumped... And i don't want to have to use colliders but if it is impossible to do otherwise, i will. Also i dont' want to have to use Colliders, but if there is no other way, i will (duh)

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
0

Answer by kingartur3 · Oct 10, 2017 at 12:56 AM

You can create a script called PrefabInfo like this:

 class PrefabInfo {
     public Vector3 size;
 }

And you can use it to store infos about the size of that particular prefab, in this way you don't have to deal with calculations but just use the raw values.

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 Concavebark · Oct 26, 2017 at 07:24 PM 0
Share

I keep running into the problem of not having any prefabs created in ![alt text][1]between the x and z axis's

Problem Shown here: [1]: https://puu.sh/y7Q9G/e19038daa7.png

any idea on how i could fix this?

avatar image
0

Answer by jmgek · Oct 26, 2017 at 09:43 PM

 //This controls the amount of tiles spawned
 public int squared = 10; 
 //This is the array of prefabs you want to spawn 
 public GameObject[] prefabs; 
 
 for(int i = 0; i < squared; i++){
     for(int j = 0; j < squared; j++){
         //Instance the prefabs along the tiles, randomly  choosing a prefab in the array by the range of the length of the array. 
         GameObject spawnedObj = Instantiate(prefabs[Random.Range(0, prefabs.Length)], new Vector3(i, 0, j), Quaternion.identity);
           //Change the rotation if you want to "Spice it up" 
     }
 }
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

103 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 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 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 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 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Instantiate prefab (button, texture) with attached script 1 Answer

Copy prefab to new object then change its vertices 1 Answer

my object keeps cloning is self i want it to clone once 2 Answers

Instantiate PreFab with C# Script 5 Answers

Instantiate A Prefab 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