How to make an object appear when another is collected?

Hi, i’m new to unity, I have made roll-a-ball game following the tutorials on unity. now i want change it so only 2 pick up objects are displayed when you open the game and then when you collect them another 2 of the pick up objects appear. Please help me!

I haven’t looked at the tutorial yet but I’m guessing the amount of objects are predefined, as in they are all created at initialization of the game by the Scene and not Script.

There are many ways to do this.

1- Spawn in the objects into the Scene and have a list of all the pickup objects.

  • This involves setting them all as ‘SetActive(false)’ then randomly selecting two at the beginning and
    doing a ‘SetActive(true)’

2- Use the GameObject.Find methods on ‘Picks Ups’ and select which children you want to set asActive

3- etc

Next have a counter of some sort that increments when a player hits a pick up object, in your Update function, you can check if the counter is equal to 2, then set two random pick up objects as ‘SetActive(true)’

If you need actual code code, I can write that too but figuring it out on your own is much more fun.

The simplest solution to this that I can think of, is as follows:

Make a Game Manager empty gameobject on your scene.
Make a GameManager script for said game object.

In your GameManager, have an array of predetermined objects to pick up.

In your pickup objects, when you collide, call a function on GameManager that they’ve been picked up.
Disable the pickup object.

On GameManager, when called “PickedUp” function, add your points or whatever, then randomly select 2 gameobjects from the array and enable them.