So I have a game where the main idea is to get balls into goals. In one level, there are soccer goals all around. The balls need to disappear when they get in the nets. I have used a script called “Score” in C#, attached to the ball object and tried DestroyObject(gameobject) as that would make the balls disappear. However, I found it doesn’t always do it, especially after you restart the level. and does not seem like people online like people destroying objects like so. For my game, these balls do not need to respawn. Once they are gone, they are gone. Just restarting the level where everything resets, but that’s already done for me somewhere else. So here is what I had.
void OnCollisionEnter(Collision collision)
{
if(collision.gameObject.name == "Goalposts" || collision.gameObject.name == "FootyGoals" ||
collision.gameObject.name == "GoalCollider" || collision.gameObject.name == "Goal ring")
{
Destroy (this.gameObject);
//I understand what gameobject.SetActive(false) could do, but it wouldn’t do the similar idea of making it invisible.
}
}