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

Item Drops on enemy spawn and death?

$
0
0
so I have a health potion to drop on the enemy death when it basically collides with my other objects and the giving it a random chance 25% at the moment to drop the item (potion). but currently it is dropping on both spawn and destroy. some help would be amazing :D using System.Collections; using System.Collections.Generic; using UnityEngine; public class DestroyAI : MonoBehaviour { public GameObject Healthpot; public float dropRate = 0.25f; //25% drop chance public Transform HealthPotSpawn; void OnCollisionEnter (Collision col) { if (col.transform.tag == "Bullet") Destroy (gameObject); else if (col.transform.tag == "Player") Destroy (gameObject); else if (col.transform.tag == "Enemy") Destroy (gameObject); else if (col.transform.tag == "Gooba") Destroy (gameObject); if (Random.Range (0f, 1f) <= dropRate) Instantiate (Healthpot, HealthPotSpawn.position, HealthPotSpawn.rotation); } }

Viewing all articles
Browse latest Browse all 274

Trending Articles



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