How to make an enemy to deviate from shots?

I want to make an IA of my game . I need a way to get the shots (prefabs) in the game to compare with the enemy , and the enemy to deviate .

I’ve already tryed to put the prefabs in the variables on script but it didn’t work.
I want to get the shots and compare with the enemy position .

How can I do it?

Please I’m beginner on unity.

By your explanation, do you mean you want the enemy to strafe away from incoming shots (bullets)? If so, are the enemies facing the player? Or wherever the shots are coming from?

If so, then you can do a raycast from the enemy, to the player. If there’s a collider hit for a bullet, then strafe the enemy. You can also do a check for distance on the incoming bullet, if the bullet is say, less than 1 unit away, strafe. Otherwise, don’t

Raycast: Unity - Scripting API: Physics2D.Raycast
Distance: Unity - Scripting API: Vector2.Distance

There are simple steering behaviour AI methods that you can find that will allow the unit to automatically try to avoid other objects without needing user input. This link looks at collision avoidance, but you can combine them to give more flexibility :

Combine this with functionality such as Ray cast to track the enemy projectile wrt your position, and it will try to adjust it for avoidance. You can also place a radius of movement around your unit to stop it going too far. There is a good book called The Nature Of Code by Daniel Shiffman, which explains them all very well.

Note these are very simple compared to technology we see these days, but I guess you should aim for a solution that is as simple as your needs require.

Hope it helps

I’ve seen about ray and raycast and I got make the shoots to fire a ray.

Well, my game is this way. I’m using ray when the shots have created. Now I want that the enemy( red nave) catch these rays to move to any side.

Do I need do the verification on the same script of the shots?
Because on the enemys’s script I’m going to need catch the rays, but not when the game has started.

Is my idea correct?
What is the best way to do it? I’m so beginner.