- Home /
This post has been wikified, any user with enough reputation can edit it.
Question by
Uzochukwu · Jul 08, 2015 at 09:26 AM ·
c#collisioninstantiate
Need help on spawning of objects from random brick in a brick breaker game
Hello, please i need help. I am working on a 2d brick breaker game and i want some of the bricks to spawn an object when it is destroyed and the object upon falling on the paddle increases live by one. I have this code in my brick script. The challenge with this is that all the bricks spawn the object attached. I just want only a random number to spawn the attached object.
void Spawn(){ Vector3 position = transform.position; foreach (GameObject item in star){
if (item != null){
GameObject items = Instantiate(item, position, Quaternion.identity) as GameObject;
items.GetComponent<Rigidbody2D>().velocity = new Vector3(0, -2f, 0);
}
}
}
Comment