Quantcast
Channel: Questions in topic: "item"
Viewing all articles
Browse latest Browse all 274

Random drop rate problem

$
0
0
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?

Viewing all articles
Browse latest Browse all 274

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>