suggesting the ball to safe direction off being hit using guitexture

Hii Since i am working with a ball game & looking for some good solution for below problem.

  1. 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.

Thanks!!!

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.

#pragma strict

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 = "";

function Update()
{
	if ( (Ball_1.position - Player.position).magnitude < (Ball_2.position - Player.position).magnitude )
	{
		closestBall = Ball_1;
	}
	else
	{
		closestBall = Ball_2;
	}
	
	if (Player.position.x < closestBall.position.x)
	{
		guiString = goLeft;
	}
	else
	{
		guiString = goRight;
	}
}

function OnGUI()
{
	GUI.Box(Rect((Screen.width/2) - 50, 10, 100, 30), guiString);
}

http://docs.unity3d.com/Documentation/ScriptReference/Vector3-magnitude.html