• 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 Louca_Coles · Jul 03, 2015 at 07:41 AM · instantiateinstantiate prefab

How to instantiate an object on multiple positions?

So I have built a cheat code system, where you enter a code on the screen and then when you load up the leaves the cheats would kick in. Some are more easter eggs than cheats, sorta like in the lego games, where the jedis are using a broom instead of a lightsabers, mine would spawn masks onto all the characters on the screen (see below image). Ive put an empty game object as a child of each of the characters, where there heads would be.

alt text

The problem is either the code im using to put all of the empty child objects into an array isnt doing its job or the instantiate code im using isnt working. I had a version that worked, but that was before the cheat system was implemented which was a public array so that I can drag each object into the array but since the cheat code system is in a different scene, I had to make it so that the object that contained the cheat code system didn't delete when loading other levels, which means when each level is loaded the code would have to find each object itself. THe code works in a sense but doesnt spawn the masks, either because the array is empty or the instantiate code is wrong, but when I test the code the debug logs are activated so it is going through each step.

This code is used to activate the cheat when the actual level is loaded.

 if (Application.loadedLevel == 1)
         {
           
             maskSpawnPoints = GameObject.FindGameObjectsWithTag("maskSpawnPoints");
         
             if (spawningMasks == true)
             {
                 if (koalaCheatActivated == true)
                 {
                     Debug.Log("Spawning Masks");
                     StartCoroutine(SpawnKoalaMasks());
                     spawningMasks = false;
                 }
                 /*if (catCheatActivated == true)
                 {
                     StartCoroutine(SpawnCatMasks());
                 }*/
             }
         }


And this is the Initiator code

 IEnumerator SpawnKoalaMasks()
     {
         Debug.Log ("Spawning Koala Masks");
         yield return new WaitForSeconds(1.0f);
         for(int i = 0; i < maskSpawnPoints.Length; i++)
         {
             Instantiate(koalaMask, maskSpawnPoints[i].transform.position, maskSpawnPoints[i].transform.rotation);
         }
     }

That should be everything that I could think you might need to help find a solution and thanks in advance.

spawn-issue.png (111.3 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

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

2 People are following this question.

avatar image avatar image

Related Questions

How to instantiate a prefab each time I click the UI button? (getting it only once when I click the button) 4 Answers

How to manipulate a variable of a prefab script (instantiated) while the game is runnning . 1 Answer

Instantiate with random scriptableObject 2 Answers

Instantiated object that has a collision is not firing OnCollisionEnter2D 1 Answer

Instantiating enemies in spawn points not working on Android Build 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