I'm making a 3rd person shooter and currently working on projectiles. My projectiles are rigidbodies, and when they are instantiated, they instantiate a geometry according to the weapon used. Anyway, I'm trying to make the projectile destroy itself when it collides but it don't works. Here's the code:
void Update()
{
if(Physics.CheckSphere(transform.position, 0.5f)) {
Collider[] hitted = Physics.OverlapSphere(transform.position, 0.5f, enemy);
foreach(var hit in hitted) {
hit.transform.gameObject.GetComponent<BasicAI>().damage((int)Random.Range(damageAmount[0], damageAmount[1]), sender.transform);
}
Destroy(gameObject);
}
}
Hope you can help me!