• 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 /
  • Help Room /
avatar image
Question by dean904 · Mar 17, 2016 at 04:42 AM · instantiateprefabspawnspawning problemsspawnpoints

Instantiate isnt working for spawner class

Forgive me, I've found a few questions similar to this but all of the fixes have been rather semantic nuances. Im trying to spawn my 'Enemy' object, which is just a cube at the moment at 1 of 3 random spawn points in my scene.

 using UnityEngine;
 using System.Collections;
 
 public class Spawner : MonoBehaviour {
 
     public GameObject Enemy;
     GameObject[] objs;
     int top;
 
     void Start()
     {
         objs = GameObject.FindGameObjectsWithTag("Spawn_Point");
         top = objs.Length;
         InvokeRepeating("CreateObject", 0.01f, 5.0f);
     }
 
     void CreateObject()
     {
         Instantiate(Enemy, objs[Random.Range(0,top)].GetComponent<Transform>().position, Quaternion.identity);
     }
 
     void Update () {
         Instantiate(Enemy, new Vector3(1, 2, 1), Quaternion.identity);
     }
 }
 

Neither the CreateObject() or Update() functions create a new object. Even the basic code given in the instantiate documentation fails.

 using UnityEngine;
 using System.Collections;
 
 public class TestInstantiate : MonoBehaviour {
 
         public GameObject prefab;
 
         void Start()
         {
         for (int i = 0; i < 10; i++)
                Instantiate(prefab, new Vector3(i * 2.0f, 0, 0), Quaternion.identity);
         }
     }

Heres a picture of my unity scene with the settings on my Enemy prefab. [1]: http://i.imgur.com/BoW8q4v.png

Comment

People who like this

0 Show 0
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

  • Sort: 
avatar image

Answer by dean904 · Mar 17, 2016 at 04:48 AM

Well, I feel stupid. I needed to apply the scripts to an object in my scene. Placing the scripts on the ground object activated the scripts and everything began working.

Comment

People who like this

0 Show 0 · 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

Unity Answers is in Read-Only mode

Unity Answers content will be migrated to a new Community platform and we are aiming to launch a public beta on June 13. Please note, Unity Answers is now in read-only so we can prepare for the final data migration.

For more information and updates, please read our full announcement thread in the Unity Forum.

Follow this Question

Answers Answers and Comments

61 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

Related Questions

Instantiate PreFab on trigger location 0 Answers

Can I spawn with an array in order? 2 Answers

Spawn enemies so they aren't instantiated on top of each other (C#) 2 Answers

Spawn in a different and random Spawn point from a list 0 Answers

Want to instantiate Prefab in its parent. 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