Quantcast
Channel: Questions in topic: "parenting"
Viewing all articles
Browse latest Browse all 302

Gameobjects do not get parented properly, double gameobjects after instanciating

$
0
0
I am trying to spawn Units (Prefabs) and parent them to an empty gameobject and destroy the old one beforehand. Destroying works just fine. I have two Problems here. First i get a second empty game object (not named (clone)) and i get an aditional Unit which is named like my prefab although i rename them. My second Problem is just one Unit gets parented to the empty game object. The rest is unparented in the hierarchy. [link text][1] using UnityEngine; using System.Collections; using UnityEngine.UI; using System; public class RegimentSpwan : MonoBehaviour { public Text row; public Text unitAmmount; public GameObject Unit; private GameObject _newGO; public void OnclickNewRegiment() { Destroy(GameObject.Find("Regiment")); _newGO = new GameObject("Regiment"); Instantiate(_newGO, this.transform.position, Quaternion.identity); for (int i = 0; i < Convert.ToInt16(row.text); i++) { for (int j = 0; j < Convert.ToInt16(unitAmmount.text); j++) { Instantiate(Unit, this.transform.position, Quaternion.identity); Unit.name = "Unit_" + i + "_" + j; Unit.transform.parent = _newGO.transform; } } } } [1]: http://imgur.com/a/qPXZD

Viewing all articles
Browse latest Browse all 302

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>