I want to destroy a created prefab (not all the prefab) and change the color or creating a new prefab on it. I figure out how to create a new image by using Instantiate on the destroyed position and/or changing the color by using renderer material color. But I want to know how to destroy 1 prefab/clone object that use Instantiate first before doing the rest. Anyone can give me hint or idea on how to do it? Tried using Destroy(this.gameObject), Destroy(gameObject), Destroy(GameObject.FindWithTag), etc but they destroy all of my life.
using UnityEngine;
using System.Collections;
public class Life : MonoBehaviour {
private GameObject gc;
private GameControl gcs;
public GameObject lifePrefab;
// Use this for initialization
void Start () {
gc = GameObject.Find ("GameControl");
gcs = gc.GetComponent<GameControl>();
}
// Update is called once per frame
void Update () {
// Get the current life from GameControl
if(gcs.getLife() == 2){
// Some code here to destroy 1 prefab life
// Create new different prefab at the same position
Vector3 newLifePos = new Vector3(-1.4f,0.6f,0);
Instantiate(lifePrefab, newLifePos, Quaternion.identity);
}
}
}