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 akitsu · Nov 26, 2013 at 01:29 PM · gameobjectspawnplatformermovingboxcollider

Spawn moving GameObjects with identical gaps!

So I am trying to spawn platforms with identical gaps. I have different three different kind of sizes of these platforms and I want to spawn them with same gap even they are different size.

 public class Spawner : MonoBehaviour
 {
     private GameObject[] platform;
     private bool spawn;
     private GameObject rollingEnemy;
     Vector3 oldSpawnPos;
     GameObject platformClone;
     public float spawnTime;
 
     void Start() 
     {
         platform = new GameObject[3];
         platform[0] = Resources.Load("Level/Platform1") as GameObject;
         platform[1] = Resources.Load("Level/Platform2") as GameObject;
         platform[2] = Resources.Load("Level/Platform3") as GameObject;
         spawn = true;
         spawnTime = 1.5f;
         oldSpawnPos = Vector3.zero;
     }
 
     void Update() 
     {
         // Spawns new platform
         if(spawn)
         {
             StartCoroutine(spawnPlatforms());
         }
     }
 
     IEnumerator spawnPlatforms()
     {
         spawn = false;   
         int randomPlatform = Random.Range(0, 2);
 
         // New platform
         platformClone = Instantiate(platform[randomPlatform], Vector3.zero, Quaternion.identity) as GameObject;
         platformClone.transform.position = new Vector3(oldSpawnPos.x + (platformClone.GetComponent<BoxCollider>().size.x / 2) + 5f, 0f, 0f);
         oldSpawnPos = platformClone.transform.position; 
 
         yield return new WaitForSeconds(spawnTime);
         spawn = true;
     }
 }


Here is also wonderful picure what I'm trying to do :D! alt text

Thanks already for answering! Every answer is closer to the solving the problem!

movingobjects.png (17.5 kB)
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by akitsu · Nov 26, 2013 at 04:20 PM

I did got it work, if anyone want same kind of platform spawning as Kiwi Run or you find in endless runners I can give the code if needed :D

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 KiraSensei · Nov 26, 2013 at 04:21 PM 0
Share

You may explain how you did it now, if someone is looking for the same thing and runs onto this question :)

avatar image hfpngaming · Jun 19, 2014 at 03:57 AM 0
Share

if you could, please show me how you fixed this problem as it would help me solve another problem

avatar image skyyguy · Jun 23, 2016 at 05:07 AM 0
Share

Hi, I am in desperate need of similar code. I am having the same problem. Would you help me out? Id really appreciate it

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

18 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

Related Questions

Slender pages collection does not activate gameobject I want 0 Answers

How i generate Gameobjects list? 0 Answers

Spawning GameObjects with help of classes --- Attaching classes to GameObjects 1 Answer

How to spawn only one GameObject from a list of game objects? Please help. 1 Answer

Turning a menu on and off onclick in hololens 0 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