I know of the Instantiate(gameObject) method, but I don’t know how to make a reference to a gameObject. I have a sprite called redCircle in my game. I have a condition in my yellow circle script that says if there is a collision, there is a chance for a new red circle to spawn at a random location on the screen.
Here is my code for what I’m trying to do:
public var redCircle: GameObject; //this is at top of file
//Generate random pos on screen for red circle
screenPos.Set(Random.value * Screen.width,Random.value * Screen.height,10);
worldPos = Camera.main.ScreenToWorldPoint(screenPos);
worldPos.z = 0;
circleInstance = Instantiate(redCircle, worldPos, Quaternion.identity) as GameObject;
I have made my redCircle sprite a rigidBody2D and it has a box collider. When I hit a yellow circle, my game freezes for a half of a second and then keeps going with no new redCircle. The method I use for giving its location is the same as when move my yellow circle to a new position so it should be appearing on the screen.