Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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 sandermander · Jul 09, 2015 at 03:16 PM · instantiateprefabarraybounds

Array of prefabs with different sizes stick to each other

Hello, Im quite new to Unity and coding. (really like it though) :) I'm struggling with a prefab array that I instantiate and move. See the code below. I attached a separate script to the prefabs with a x.movement like this transform.Translate(Vector3.right

Now the prefabs are instantiated on a timer and they move in the x position. But this is not what I want. The prefabs are different sizes in the x. I want my instantiate to know what the sizes are and instantiate them with a given gap in between. I did a lot of googling and came across bound.size.x and renderer.bound. I think I need to calculate the timer to a prefab bound size x, but don't know how... Also I think I need the movement script in this timer, not as a separate script. Am I on the right track? Can anyone give me some clues?
Thanks!

         private float timer = 0.0f;
     private float TimeToRespawn = 2.0f;
     
     public Transform[] Spawns;
     public GameObject[] Prefabs;
     
     void FixedUpdate () {
         timer += Time.fixedDeltaTime;
         if (timer >= TimeToRespawn)
             SpawnPFB();
         
     }
     
     
     void SpawnPFB(){
         
         timer = 0;
         
         int tele_num = Random.Range(0,1);
         int prefeb_num = Random.Range(0,2);
         
         Instantiate(Prefabs[prefeb_num],Spawns[tele_num].position, Spawns[tele_num].rotation);
     }
 }
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

0 Replies

· Add your reply
  • Sort: 

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

Prefabs instantiated from an array are keeping their public int value 1 Answer

Parenting an instantiated prefab. 1 Answer

Instantiating an array of objects - how can I instantiate a certain prefab only once? 1 Answer

Array of prefabs 0 Answers

OverlapSphere for parallel arrays 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