Here’s a modification to a script I picked up at the unify community for an enemy radar. I’ve added variables for collectibles and power ups. It also allows for three different blips for whatever your tracking so that you can tell a difference in what’s on the radar. Another use would be to use different blips for different enemy states such as full life, hurt, dead, attacking, or whatever your game calls for. Those could easily be changed to enemy type 2 and enemy type 3, ect. Probably not useful to most, but a newbie like myself might find it of use.
@script ExecuteInEditMode()
var blip : Texture;
var blip2 : Texture;
var blip3 : Texture;
var radarBG : Texture;
var centerObject : Transform;
var mapScale = 0.3;
var mapSizePercent = 15;
var checkAIscript : boolean = true;
var enemyTag = "Enemy";
var collectibleTag = "Collectible";
var pickupTag = "Pickup";
enum radarLocationValues {topLeft, topCenter, topRight, middleLeft, middleCenter,
middleRight, bottomLeft, bottomCenter, bottomRight, custom}
var radarLocation : radarLocationValues = radarLocationValues.topCenter;
private var mapWidth : float;
private var mapHeight : float;
private var mapCenter : Vector2;
var mapCenterCustom : Vector2;
function Start(){
setMapLocation();}
function OnGUI (){
if(!centerObject){
return;}
bX = centerObject.transform.position.x * mapScale;
bY = centerObject.transform.position.z * mapScale;
GUI.DrawTexture(Rect(mapCenter.x - mapWidth/2, mapCenter.y - mapHeight/2,
mapWidth, mapHeight), radarBG);
DrawBlipsForEnemies();
DrawBlipsForCollectibles();
DrawBlipsForPickups();
}
function drawBlip(go, aTexture){
centerPos = centerObject.position;
extPos = go.transform.position;
dist = Vector3.Distance(centerPos, extPos);
dx = centerPos.x - extPos.x;
dz = centerPos.z - extPos.z;
deltay = Mathf.Atan2(dx,dz) * Mathf.Rad2Deg - 270 - centerObject.eulerAngles.y;
bX = dist * Mathf.Cos(deltay * Mathf.Deg2Rad);
bY = dist * Mathf.Sin(deltay * Mathf.Deg2Rad);
bX = bX * mapScale;
bY = bY * mapScale;
if(dist <= mapWidth * .25/mapScale){
GUI.DrawTexture(Rect(mapCenter.x + bX, mapCenter.y + bY, 4,4),aTexture);
}}
function drawBlip2(co, aTexture){
centerPos = centerObject.position;
extPos = co.transform.position;
dist = Vector3.Distance(centerPos, extPos);
dx = centerPos.x - extPos.x;
dz = centerPos.z - extPos.z;
deltay = Mathf.Atan2(dx,dz) * Mathf.Rad2Deg - 270 - centerObject.eulerAngles.y;
bX = dist * Mathf.Cos(deltay * Mathf.Deg2Rad);
bY = dist * Mathf.Sin(deltay * Mathf.Deg2Rad);
bX = bX * mapScale;
bY = bY * mapScale;
if(dist <= mapWidth * .25/mapScale){
GUI.DrawTexture(Rect(mapCenter.x + bX, mapCenter.y + bY, 4,4),aTexture);
}}
function drawBlip3(po,aTexture){
centerPos = centerObject.position;
extPos = po.transform.position;
dist = Vector3.Distance(centerPos, extPos);
dx = centerPos.x - extPos.x;
dz = centerPos.z - extPos.z;
deltay = Mathf.Atan2(dx,dz) * Mathf.Rad2Deg - 270 - centerObject.eulerAngles.y;
bX = dist * Mathf.Cos(deltay * Mathf.Deg2Rad);
bY = dist * Mathf.Sin(deltay * Mathf.Deg2Rad);
bX = bX * mapScale;
bY = bY * mapScale;
if(dist <= mapWidth * .25/mapScale){
GUI.DrawTexture(Rect(mapCenter.x + bX, mapCenter.y + bY, 4,4),aTexture);
}}
function DrawBlipsForEnemies(){
var gos : GameObject[];
gos = GameObject.FindGameObjectsWithTag(enemyTag);
var distance = Mathf.Infinity;
var position = transform.position;
for (var go : GameObject in gos){
drawBlip(go, blip);}}
function DrawBlipsForCollectibles(){
var cos : GameObject[];
cos = GameObject.FindGameObjectsWithTag(collectibleTag);
var distance = Mathf.Infinity;
var position = transform.position;
for (var co : GameObject in cos){
drawBlip2(co, blip2);}}
function DrawBlipsForPickups(){
var pos : GameObject[];
pos = GameObject.FindGameObjectsWithTag(pickupTag);
var distance = Mathf.Infinity;
var position = transform.position;
for (var po : GameObject in pos){
drawBlip3(po, blip3);}}
function setMapLocation(){
mapWidth = Screen.width * mapSizePercent/100.0;
mapHeight = mapWidth;
if ( radarLocation == radarLocationValues.topLeft){
mapCenter = Vector2(mapWidth/2, mapHeight/2);}
else if ( radarLocation == radarLocationValues.topCenter){
mapCenter = Vector2(Screen.width/2, mapHeight/2);}
else if ( radarLocation == radarLocationValues.topRight){
mapCenter = Vector2(Screen.width - mapWidth/2, mapHeight/2);}
else if (radarLocation == radarLocationValues.middleLeft){
mapCenter = Vector2(mapWidth/2, Screen.height/2);}
else if (radarLocation == radarLocationValues.middleCenter){
mapCenter = Vector2(Screen.width/2, Screen.height/2);}
else if (radarLocation == radarLocationValues.middleRight){
mapCenter = Vector2(Screen.width - mapWidth/2, Screen.height/2);}
else if (radarLocation == radarLocationValues.bottomLeft){
mapCenter = Vector2(mapWidth/2, Screen.height - mapHeight/2);}
else if (radarLocation == radarLocationValues.bottomCenter){
mapCenter = Vector2(Screen.width/2, Screen.height - mapHeight/2);}
else if (radarLocation == radarLocationValues.bottomRight){
mapCenter = Vector2(Screen.width - mapWidth/2, Screen.height - mapHeight/2);}
else if (radarLocation == radarLocationValues.custom){
mapCenter = mapCenterCustom;}
}
I have more stuff from the game, but not sure what’s useful to post here.