Hello!
Let me explain the scenario first…
I have a character which places a bomb at the same spot he is currently.
After 2.6sec bomb should explode and destroy what’s in its way, that should be the box when character is out of way.
The problem is that it always kills the character too, although I set 2.5 sec delay, and if the last updated hit returns box, shouldn’t it destroy only a box?
I tried using coroutines to time Raycast and Destroy just before bomb disappears, but nothing happens when bomb disappears…
The raycast happens instantly, and records the first object it hits. When you set 2.5f delay on the Destroy, that delays the Destroy, not what gets destroyed.
What happens in your code now is that every fixed update, which is quite often - the bomb checks what’s directly above it, and sets that object to be destroyed in 2.5 seconds.
Assuming you place the bomb by using Instantiate, you get the behavior you want by using a Coroutine, like this:
Note that the bomb still only destroys stuff that’s directly above it. If you want to destroy everything around it, you need to use Physics2D.OverlapCircleAll.