I have a bomb explosion script where i press space to make a bomb explode.
void Update()
{
if (Input.GetKeyDown(KeyCode.Space))
{
Debug.Log("Test");
explode();
}
}
void explode()
{
Collider2D[] objects = Physics2D.OverlapCircleAll(transform.position, fieldofImpact, LayerToHit);
foreach(Collider2D obj in objects)
{
Vector2 direction = obj.transform.position - transform.position;
obj.GetComponent().AddForce(direction * force);
}
}
When i press space i get the "Test" message in console along with:
UnassignedReferenceException: The variable explosion of ExplodeBomb has not been assigned.
You probably need to assign the explosion variable of the ExplodeBomb script in the inspector.
The script is assigned only to the bomb object.
If i execute the explode function in void update with no condition before, it works, in the way that it continuously explodes, of course.
Tried using both Unity 2019 & 2020.
↧