var itemDrop : GameObject;
var enemyHealth : int = 1;
var dropRate : float = 0.25; //25% chance of dropping
function OnCollisionEnter(theCollision : Collision)
{
if (theCollision.gameObject.tag == "Player")
{
enemyHealth -=1;
if(enemyHealth <= 0)
{
Destroy(gameObject);
if(Random.Range(0,1) <= dropRate)
{
var pickupDrop = Instantiate(itemDrop, gameObject.transform.position, Quaternion.identity);
}
}
}
}
Above is the code I have for my random drop rate, when I destroy my enemies I would like it to have a 25% chance of dropping my item, but as I have it now, it happens all the time.
Can anyone point out where I'm going wrong please?
↧