Hello everyone. I’m following a tutorial and I’m getting this error. The code is simply
public class Detonator : DamageReceiver
{
public float m_MinRadius = 4.0F;
public float m_MaxRadius = 4.0F;
///@todo: How do we constrain min radius to always be smaller than max radius.
/// But with a good interface (The value the user edits should stay the other should be clamped!)
public float m_Damage = 10F;
// public LayerMask m_DetonateAgainst = -1;
public float m_DetonationDelay = 0F;
public GameObject explosion;
public GameObject wreck;
bool m_IsDetonated = false;
public virtual void Detonate ()
{
// Only detonate once!
if (m_IsDetonated)
return;
m_IsDetonated = true;
Invoke ("DetonateImplementation", m_DetonationDelay);
}
void DetonateImplementation ()
{
// Instantiate wreck and explosion if availible
if (explosion != null)
InstantiateWithMovement (explosion);
if (wreck != null)
InstantiateWithMovement (wreck);
// Destroy the object itself
DestroyObject (gameObject);
// Apply damage to surrounding objects!
DamageReceiver wreckReceiver = null;
if (wreck != null)
wreckReceiver = wreck.GetComponent (typeof (DamageReceiver)) as DamageReceiver;
ApplyDetonationDamage (wreckReceiver);
}
// Instantiates the game object with the position and velocity of this game object!
void InstantiateWithMovement (GameObject go)
{
go = (GameObject)Instantiate (go, transform.position, transform.rotation);
if (go.rigidbody != null && rigidbody != null)
{
go.rigidbody.velocity = rigidbody.velocity;
go.rigidbody.angularVelocity = rigidbody.angularVelocity;
}
}
void ApplyDetonationDamage (DamageReceiver exclude)
{
DamageMessage damage = new DamageMessage (DamageMessage.DamageType.kExplosionSplashDamage, m_Damage, transform.position, m_MinRadius, m_MaxRadius);
**Collider[] collisions = Dynamics.OverlapSphere (transform.position, m_MaxRadius); // This seems to be the problem **
foreach (Collider collider in collisions)
{
DamageReceiver receiver = collider.GetComponent (typeof (DamageReceiver)) as DamageReceiver;
if (receiver != null && receiver != this && receiver != exclude)
{
receiver.ApplyDamage (damage);
}
}
}
}
What’s causing this?