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 ragefordragons · Jan 01, 2018 at 11:59 PM · prefabspawninghalf

Only half of a prefab is spawning?

So I have created a spawner to spawn an enemy in my game. The enemy is a prefab consisting of two 3d triangles, with one the child object of the other. This code for spawning works fine for prefabs that only consist of one part, but when it tries to spawn this other enemy, only half of it (the child object) is spawned. Here is the spawner code: Any Ideas?

using System.Collections; using System.Collections.Generic; using UnityEngine;

public class MonsterSpawner2 : MonoBehaviour {

 public float delta = 1.5f;
 public float speed = 2.0f;
 private Vector3 startPos;
 public Transform spawnpoint;
 public GameObject redshell;

 public int EnemySpeed = 7;
 public int enemiesleft = 10;

 public bool useInvoke;
 public bool running;


 // Use this for initialization
 void Start () {
     if (useInvoke)
         InvokeRepeating("redspawn", 0, 3);
     else
         StartCoroutine(spawnred());
 }
 
 // Update is called once per frame
 void Update () {

     if (enemiesleft < 1)
     {
         Destroy(gameObject);
     }
 }

 IEnumerator spawnred()
 {
     running = true;

     while (running)
     {
         if (PlayerController.stomata > 1699)
         {
         enemiesleft = enemiesleft - 1;


         spawnredshell();
         yield return new WaitForSeconds(0f + (Random.Range(1.5f, 3f)));
         continue;
         }

         yield return null;

     }


 }


 void spawnredshell()
     {
     var shellspawn = (GameObject)Instantiate(
         redshell,
         spawnpoint.position,
         spawnpoint.rotation);

     shellspawn.GetComponent<Rigidbody>().velocity = shellspawn.transform.up * EnemySpeed;

     Destroy(shellspawn, 10.0f);


 }

}

Comment
Add comment · Show 3
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 ragefordragons · Jan 02, 2018 at 12:02 AM 0
Share

*Actually I think its the Parent Object that is only getting spawned.

avatar image David_Rios ragefordragons · Jan 02, 2018 at 04:04 AM 0
Share

Is the child of the parent GameObject also a child of that GameObject in the prefabs file? Either way, you can respawn the child object as a prefab as a child of the parent gameObject.

avatar image ragefordragons David_Rios · Jan 02, 2018 at 08:39 PM 0
Share

Sorry, im not sure what you mean. Are you saying that I need to spawn both peices of the prefab in the code? Does each peice need to be its own prefab?

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by OneCept-Games · Jan 02, 2018 at 08:46 PM

Drag you Prefab into your scene, and check if it is as you expect. It sounds like you have just prefabbed the child in this case.

Comment
Add comment · Show 7 · 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 ragefordragons · Jan 03, 2018 at 03:17 AM 0
Share

Okay... so do I need to make the child not a prefab? how do I do this?

avatar image OneCept-Games ragefordragons · Jan 03, 2018 at 08:45 AM 0
Share

To test if you have created your Prefab correctly, drag it into your Scene, and see if it contains both a parent and a child.

avatar image ragefordragons OneCept-Games · Jan 03, 2018 at 03:12 PM 0
Share

Just to be clear, you mean that the prefab has the second part of it dragged under it so you can view it by clicking the drop down menu next to the parents name, correct? If so, yes it has a parent and a child.

Show more comments

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

91 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

Related Questions

,Getting a Spawner Manager Script to reference a Spawner 1 Answer

How do I get an object to Instantiate infront of a specific object/player? 1 Answer

SOLVED : Adding and retrieving instantiated objects from Array 1 Answer

Disfigured sprite after build. 0 Answers

How do you spawn multiple prefabs within a certain distance from each other from one spawn point? 2 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