New answers tagged

5

The best way to do this depends on a few things. I'm going to assume the following - if any of these are incorrect, please let me know and I'll update my answer: You want the closest enemy that is anywhere to the right of the player within a certain range, even if it is at a different height You want true distance, not just the one that is closest in ...


1

Assuming your enemies all have colliders, could you not simply fire a 2D Raycast https://docs.unity3d.com/ScriptReference/Physics2D.Raycast.html in a straight line to the right of your player and return the GameObject of the first collider it hits?


-1

Made it work by assigning a "Left Side" tag to the enemies on the left and a "Right Side" tag to the enemies on the right. After that I find the closest enemy on a particular side by checking the distance from the enemy to the player and returning the closest one: private GameObject FindClosestEnemy(string side) { GameObject[] enemies = GameObject....


2

All the left enemy are in lower value in x-axis position. Objects on right side are on higher value. Subtract main character's x value from enemy's. Positive results are for enemies at right side.


1

I have dabbled in some dragging and snapping behavior before. This script allows you to drag a cube, changes its color when its near the object to snap to and then snaps it to the right axis when you release the mouse. Sadly it has no code for dragging the object while its snapped to the wall but it might be a good starting point. Here is the code : using ...


-1

As far as I know Unity has only has snapping to grid by holding down Ctrl (Cmd on mac). Unity has a tutorial for it here


0

Physics2D.OverlapArea would be perfect for this use...


0

Are you using "unity mecanim" to play these animations or are you using legacy. If you are using legacy, I don't think it is possible but with mecanim you should be able to do something like this, even though I never tried it. Just find some tutorials on it and try and implement the thing you want to do. I would recommend this tutorial, I used it to get ...



Top 50 recent answers are included