Percent Chance

I want to make it that so when I break a block, there is a chance that it will drop a power up such as having extra balls. For example, if i break a block there is a 40% chance it will drop this power up and when it touches the paddle another ball will spawn. I want to know how to make it so that there is a percent chance of when something will happen.

Hi Zaki,

When the Block gets destroyed, you could instantiate a “bonus” prefab in the same method where you instantiate the prefab with the particle system.

To fake randomness, you could do the same what you did in Number Wizard. Instead of Random.Range, I would use Random.value, which is a matter of preference, though.

For example:

[SerializeField] GameObject bonusPrefab;

public void YourMethod()
{
    if (Random.value > 0.8f) // if the returned value ranges between 0.800...1f and 1.0f
    {
        Instantiate (bonusPrefab, ...);
    }
}

I hope this helps. :slight_smile:


See also:

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms