Hi
I’m trying to create a power up designed to explode destroying everything in the blast area. Using Physics.Overlapshere I am attempting to create an array of all the colliders in the blast zone. Then I’m trying to access the objects assigned to that collider and then to access the objects attached script ‘DestroyByContact’ which I then hope to call the public function ‘Destroyed’.
I don’t think I’m far off finishing but I think I need a bit of help with accessing objects on the colliders thing.
I think I have included everything that I’m working with here. Shout out if not. ![]()
Any help would be great please.
Cheers ![]()
My code
Bomb script (as you can probably see, I get lost once I get into the code following ‘if (col.collider.tag’ ) ![]()
public class Bomb : MonoBehaviour
{
public Transform explosionPosition = transform.position;
public float explosionRadius = 10.0;
public Collider[] colliders = Physics.OverlapSphere(explosionPosition, explosionRadius);
private GameObject victim;
void OnTriggerEnter(Collider other)
{
if (other.tag == "Player")
{
Destroy(gameObject);
Explode();
}
else
{
return;
}
}
void Explode()
{
foreach (Collider col in colliders)
{
if (col.collider.tag == "LargeHazard" | col.collider.tag == "MediumHazard" | col.collider.tag == "Hazard")
{
//Destroy(col.collider.gameObject);
GameObject victimObject = Collider.gameObject;
victim = victimObject.GetComponent<DestroyByContact>();
victim.Destroyed();
}
}
}
}
DestroyByContact (I’ve only included the function I want to call)
public void Destroyed()
{
gameController.AddScore(scoreValue);
}