So my setup is: I have some large glass displays. The player can break them by punching them. I do this like this:
private void OnCollisionEnter(Collision collision)
{
if (collision.gameObject.CompareTag("Player"))
{
if (hasText)
{
text.SetActive(false);
}
this.GetComponent<MeshRenderer>().enabled = false;
this.GetComponent<BoxCollider>().enabled = false;
shatters.SetActive(true);
}
}
Now, in the next level I want the displays to be there again, and I want them to be breakable again. So I built a Reset function:
public void Reset()
{
Destroy(shatters);
shatters = Instantiate(shattersprefab);
if (hasText)
{
text.SetActive(true);
}
this.GetComponent<MeshRenderer>().enabled = true;
this.GetComponent<BoxCollider>().enabled = true;
}
Which works well enough in making the displays visible again, but when they are punched by the player the shards are already on the groundl, just as they were left in the previous level. It seems as if I’m just re-instantiating the already fallen shards. But I have no clue how this could have happened.
I’ve been having similar problems throughout this whole project and by now I think I might just be fundamentally misunderstanding prefabs.