Hii Since i am working with a ball game & looking for some good solution for below problem.
- the enemy ball move randomly around the scene if enemy balls coming closure to player ball then we need to suggest the safe direction to the player ball by displaying the guitexture arrows like left,right,up,down like that…Eg: if enemy balls are moving closure to player ball in +z axis then the arrow should suggest the safe direction either left or right.
The escape direction is going to be the cross vector between up and player → enemy.You should check if the direction is avalaible (no walls) and if it’s not, invert it.
This is an easy way to check which object is closer, and what side of the player the object is on. You can attach this script to any gameObject (or the camera), then drag-and-drop the player and enemies into the Inspector.
public var Player : Transform;
public var Ball_1 : Transform;
public var Ball_2 : Transform;
private var closestBall : Transform;
private var goLeft : String = "Go Left";
private var goRight : String = "Go Right";
private var guiString : String = "";
if ( (Ball_1.position - Player.position).magnitude < (Ball_2.position - Player.position).magnitude )
closestBall = Ball_1;
closestBall = Ball_2;
if (Player.position.x < closestBall.position.x)
guiString = goLeft;
guiString = goRight;
GUI.Box(Rect((Screen.width/2) - 50, 10, 100, 30), guiString);