Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Wanting to make a powerup...

Discussion in '2D' started by hyybrid, Jan 12, 2015.

  1. hyybrid

    hyybrid

    Joined:
    Jan 11, 2015
    Posts:
    15
    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?
     
  2. saddam751

    saddam751

    Joined:
    Nov 6, 2013
    Posts:
    41
    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).
     
    hyybrid likes this.
  3. hyybrid

    hyybrid

    Joined:
    Jan 11, 2015
    Posts:
    15
    Okay awesome however, how would I then make it a random drop?
     
  4. BlaXun

    BlaXun

    Joined:
    Jan 8, 2015
    Posts:
    52
    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
     
  5. hyybrid

    hyybrid

    Joined:
    Jan 11, 2015
    Posts:
    15
    ok ty :) will try it out
     
    BlaXun likes this.