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
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);
}
}