How reuse Objects . And Destroy When Player Pass it.

I am making Color switching Game . I want that when the ball passes from a ring so i want to remove when its done . and i want game infinite so want to reuse Different rings again and again infinity . but when player lose or game over so it restart again game . kindly not give idea …provide script please

Good day.

I will not provide you the script, you need to do it by yourself to understand what are you doing, and be able to make a script for all this kind of things. But i will say you what to use:

First, you need to store the circle as a prefab, (Remebebr to store the prefab with coords (0,0,0) to be sure iot will spawn at the position you will give). So you can easy create clones of the circle where and when you want.

Once you have a prefab, you can do a script to Instantiate() clones of the prefab in the scene giving the prefab object, the position and the rotation. So first, create a public GameObject variable, and assign the prefab to the variable via inspector. Then you can use the Instantiate:

public GameObject CirclePrefab;

GameObject NewCircle = Instantiate(CirclePrefab, VectorPosition, QuaternionRotation)

This Circles, can have a script on it, that detects the “player” and destroy themselves when necessary, with this simple code:

Destroy (gameObject);

gameObject (with minus g) refears to the object that contains this script, so this line will destroy the circle. When a object is destroyed, it is deleted from the scene, forever. (But as you have a prefab stored you can continue spawning new circles.

I highly recommend you to watch some tutorials in youtube, read some manuals, etc… Instantiate() and Destroy() is one of the main functions of Unity, so you must understand and learn how to use them.

BYE!! :smiley: