public void SpawnTopping() { // remove old children objects // this deletion is required since all toppings spawned in editor mode wont be refert properly // HACK List <GameObject> children = new List <GameObject>(); for (int i = 0; i < transform.childCount; i++) { children.Add(transform.GetChild(i).gameObject); } foreach (GameObject go in children) { DestroyImmediate(go); } // spawn prefab if there is any GameObject prefab = Resources.Load <GameObject>(prefabPath + mapTile.topping.prefabName); // note: not .prefab! GameObject handle = (GameObject)Instantiate(prefab, Vector3.zero, prefab.transform.rotation); handle.transform.parent = this.transform; handle.transform.localPosition = Vector3.zero; bTopping = handle.GetComponent <BTopping>(); if (bTopping == null) { Debug.LogError("The Prefab for " + topping + " must have a BTopping component attached to!"); } }
public void DestroyTopping() { if (bTopping == null) { return; } bTopping.DestroyTopping(); bTopping = null; }