In my game a ball will drop every few seconds but when I use instantiate what happens is that it clones each ball that is in the scene. How would I go about only having one ball added to the scene every few seconds instead of doubling the number of balls in the scene?,I have a ball and it drops at the beginning of the game and after a few seconds another ball with the same features will spawn. But what happens is when it is time for a ball to spawn, the number of balls in the scene are just doubled instead of spawning a single ball every few seconds. When I use instantiate it will clone each ball that is in the scene instead of cloning one extra ball after a few seconds. How would I go about solving this problem?
Without code, I can only assume that you are instantiating the “wrong target”.
Make a prefab of the ball you want to spawn. That way you won’t need to have it in the scene).
Give your script a reference to a prefab. Instantiate that.
public class SomeClassYouProbablyHave : Monobehaviour {
// Drag a prefab to this in the editor
public Transform ballPrefab;
void ThisRunsEveryFewSeconds(){
Transform clonedBall = GameObject.Instantiate(ballPrefab) as Transform;
// do stuff with this new clone
}
}