So ive been trying to fix this problem for a while now and i can’t manage to fix it
My problem is that in one of my scripts that destroys an object, it will destroy the object and a clone of that object when destroyed. I’ve been trying to just make it destroy the clone only
So what happens, in one of my script, a white button is spawned (instantiated from an object that’s already in the hierarchy) so it spawns that object clone.
using UnityEngine;
using System.Collections;
public class WhiteClick : MonoBehaviour
{
public GameObject buttonManagerObject;
private ButtonManager buttonManager;
public GameObject whiteButton1;
public GameObject whiteButton2;
public GameObject whiteButton3;
public GameObject whiteButton4;
public GameObject whiteButton5;
public GameObject whiteButton6;
public GameObject whiteButton7;
public GameObject whiteButton8;
public GameObject whiteButton9;
// Use this for initialization
void awake ()
{
}
void Start ()
{
buttonManager = buttonManagerObject.GetComponent<ButtonManager> ();
}
// Update is called once per frame
void Update()
{
if (buttonManager.destroyWhiteButton1 == true) {
Destroy (whiteButton1);
}
if (buttonManager.destroyWhiteButton2 == true) {
Destroy (whiteButton2);
}
if (buttonManager.destroyWhiteButton3 == true) {
Destroy (whiteButton3);
}
if (buttonManager.destroyWhiteButton4 == true) {
Destroy (whiteButton4);
}
if (buttonManager.destroyWhiteButton5 == true) {
Destroy (whiteButton5);
}
if (buttonManager.destroyWhiteButton6 == true) {
Destroy (whiteButton6);
}
if (buttonManager.destroyWhiteButton7 == true) {
Destroy (whiteButton7);
}
if (buttonManager.destroyWhiteButton8 == true) {
Destroy (whiteButton8);
}
if (buttonManager.destroyWhiteButton9 == true) {
Destroy (whiteButton9);
}
}
void OnMouseUp ()
{
Debug.Log ("Game Over");
//go to highscore menu
}
}
Now in this script, it’s supposed to make the "whiteButton#'s clone disappear, but leave the normal object there (i only want the clone to be destroyed so i can instantiate more clones from that object later on. and i can’t do that if there’s no object to use to instantiate more)
i’ve tried also adding in the WhiteClick’s if statement:
buttonManager.destroyWhiteButton# = false; //# = what number button (its not actually # in the code)
(so it doesnt infinitely destroy the buttons)
if i add this statement, it will destroy the object, but it will leave the clone alone
What could i do to make it so it destroys the clone and not the object?
Thanks in advance!