So i’ve made this bomb script which consists of one IEnumerator with a raycast array inside of it, and there’s two yield return new waitforseconds inside aswell. The bomb works this way, u place the bomb, it waits for 2.5 seconds, then iterates through the loop and destroys everything with the layer whatIsDestroyable.
Everything actually works fine, but i just get a nullreference error once the bomb sets off, ie at hit*.transform.SendMessage("DamageTaken", damage, SendmessageOptions.DontRequireReciever);
the error is Grenade2+c__Iterator1.MoveNext() at cs 30*
idk if it makes sense, but i think the error comes from theres nothing to iterate through or something? what can i do to solve this? should i use a list? anyways heres the code:
public Transform pointOfCircle;
-
public float radius = 0.5f;*
-
public LayerMask whatIsDestroyable;*
-
public float distance = 1f;*
-
public int damage = 1;*
-
public float waitTime = 1f;*
-
public float timeToDestroy = 0.2f;*
-
void Update()*
-
{*
-
StartCoroutine ("Bomb");*
-
}*
-
private IEnumerator Bomb()*
-
{*
-
RaycastHit2D[] hit;*
-
hit = Physics2D.CircleCastAll (pointOfCircle.position, radius, new Vector2 (1, 1), 0.5f, whatIsDestroyable);*
-
for (int i = 0; i < hit.Length; i++)*
-
{*
-
yield return new WaitForSeconds(waitTime);*
_ hit*.transform.SendMessage(“DamageTaken”, damage, SendMessageOptions.DontRequireReceiver);_
_ yield return new WaitForSeconds(timeToDestroy);_
_ Destroy (gameObject);_
_ }*_
* }*