I just started Unity two days ago, and it is quite a big fun, but I have a problem what I can’t solve. Im making a 2D starship game where the enemy ships and asteroids are coming towards you and you have to shoot them. It’s working fine, my only problem is I made the asteroids a bit faster than the enemy ships and it’s quite weird when they are in the same y position line and the asteroid just go trough the enemy ship. My question is how can I check if there is an enemy ship in the way of the asteroid before asteroid spawning?
Thank you for your help guys!
You can do that by using raycast2D. Assuming all your 2D objects have a 2D collider, you can check from the astroids origin if anything is in front of them.The raycast will return true if anything is hit by the raycast2D.