public class Dices : MonoBehaviour {
public GameObject Dice4_1;
public GameObject Dice4_2;
public GameObject Dice4_3;
public GameObject Dice4_4;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (Input.GetMouseButtonDown(0))
{
int result = Random.Range(1, 5);
if (GameObject.Find("Dice4_1_img(Clone)") != null)
{
Destroy(Dice4_1);
}
if (GameObject.Find("Dice4_2_img(Clone)") != null)
{
Destroy(Dice4_2);
}
if (GameObject.Find("Dice4_3_img(Clone)") != null)
{
Destroy(Dice4_3);
}
if (GameObject.Find("Dice4_4_img(Clone)") != null)
{
Destroy(Dice4_4);
}
if (result == 1)
{
Instantiate(Dice4_1, transform.position, transform.rotation);
}
if (result == 2)
{
Instantiate(Dice4_2, transform.position, transform.rotation);
}
if (result == 3)
{
Instantiate(Dice4_3, transform.position, transform.rotation);
}
if (result == 4)
{
Instantiate(Dice4_4, transform.position, transform.rotation);
}
}
}
}
This gives me an error that says: To avoid lose of data bla bla bla, you should use DestroyInmediate(Object, true);
Then I change it, and it says, that DestroyInmediate doesnt exist in this contexts.
What I want is that each time I click on the object, it creates a prefab of another object (1 between 4), and if any of those 4 exists, then it should delete it, and then create the prefab that the RandomRange says.