Wanting to make a powerup...

I’m making a 2d game and my character will start with 3 lifes, however when killing the AI’s that will spawn in I want a random additional life to be dropped by them, once the character walks into this life he gains an additional life. How can I code this?

Here are steps-
1.Take a variable of int type and set it’s value to 3 in Start function.
2.In OnCollisionEnter increase it’s value by 1.For eg-x=x+1.
3.Make additional life a child of AI and make its renderer and collider off.
4.On killing AI turn off renderer of AI and turn on renderer and collider of additional power.
4.On collision with additional power destroy it and the value of life will be increased by 1 (as discussed in point 2).

1 Like

Okay awesome however, how would I then make it a random drop?

Random as in “x% drop chance”?

You can make it so u only enable the renderer when

if (Random.Range(0,1) >= 0.8) //20% drop change
…enable renderer

Do this on Destroy

ok ty :slight_smile: will try it out

1 Like