- Home /
Mini-Map Radar screen with different blips.
This is a radar script, originally made by dasterdlybanana and psychic parrot, that I've been trying to adapt to my game. Their original script works by displaying static objects on their radar screen but the blips move as their character does. It can have two blips. One if the enemy is chasing and one if the enemy is not. I want to use this same concept but have a different blip for each different shape (the shapes move around as well). This displays the background of my radar screen but it doesn't display the blips. Can anyone tell me why? Any help is appreciated. My adaption of the script is below, here's where the original code can be found: http://forum.unity3d.com/viewtopic.php?p=189482.
@script ExecuteInEditMode()
var sphere : Texture; //blip for spheres var cube : Texture; //blip for cubes var cone : Texture; //blip for cones var cylinder : Texture; //blip for cylinders var radarBG : Texture; //background texture (radar screen)
var centerObject : Transform; var mapScale = 0.3; var mapSizePercent = 15;
var sphereTag = "Sphere"; var cubeTag = "Cube"; var coneTag = "Cone"; var cylinderTag = "Cylinder";
enum radarLocationValues {topLeft, topCenter, topRight, middleLeft, middleCenter, middleRight, bottomLeft, bottomCenter, bottomRight, custom} var radarLocation : radarLocationValues = radarLocationValues.bottomLeft;
private var mapWidth : float; private var mapHeight : float; private var mapCenter : Vector2; var mapCenterCustom : Vector2;
function Start () { setMapLocation();
}
function OnGUI () { // GUI.matrix = Matrix4x4.TRS (Vector3.zero, Quaternion.identity, Vector3(Screen.width / 600.0, Screen.height / 450.0, 1));
// Draw player blip (centerObject)
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);
DrawBlipsForShapes();
}
function drawBlip(go,aTexture){
centerPos=centerObject.position;
extPos=go.transform.position;
// first we need to get the distance of the enemy from the player
dist=Vector3.Distance(centerPos,extPos);
dx=centerPos.x-extPos.x; // how far to the side of the player is the enemy?
dz=centerPos.z-extPos.z; // how far in front or behind the player is the enemy?
// what's the angle to turn to face the enemy - compensating for the player's turning?
deltay=Mathf.Atan2(dx,dz)*Mathf.Rad2Deg - 270 - centerObject.eulerAngles.y;
// just basic trigonometry to find the point x,y (enemy's location) given the angle deltay
bX=dist*Mathf.Cos(deltay * Mathf.Deg2Rad);
bY=dist*Mathf.Sin(deltay * Mathf.Deg2Rad);
bX=bX*mapScale; // scales down the x-coordinate so that the plot stays within our radar
bY=bY*mapScale; // scales down the y-coordinate so that the plot stays within our radar
if(dist<=mapWidth*.5/mapScale){
// this is the diameter of our largest radar circle
GUI.DrawTexture(Rect(mapCenter.x+bX,mapCenter.y+bY,4,4),aTexture);
}
}
function DrawBlipsForShapes(){
var gos : GameObject[];
gos = GameObject.FindGameObjectsWithTag(sphereTag && cubeTag && coneTag && cylinderTag);
var distance = Mathf.Infinity;
var position = transform.position;
// Iterate through them and call drawBlip function
for (var go : GameObject in gos) {
var blipChoice : Texture;
if(go.tag == "Sphere") {
blipChoice = sphere;
}
drawBlip(go,blipChoice);
if(go.tag == "Cube") {
blipChoice = cube;
}
drawBlip(go,blipChoice);
if(go.tag == "Cone") {
blipChoice = cone;
}
drawBlip(go,blipChoice);
if(go.tag == "Cylinder") {
blipChoice = cylinder;
}
drawBlip(go,blipChoice);
}
}
function setMapLocation () { mapWidth = Screen.width*mapSizePercent/100.0; mapHeight = mapWidth;
//sets mapCenter based on enum selection
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;
}
}
Answer by SpiritWebb · Feb 16, 2011 at 05:59 PM
You have to tag your enemy with "Enemy." To make it fully work, place the radar script on your main camera, and drag your player, tagged with "Player" to the Center Object of the radar script. Drop the EnemyAI script on your enemy, name it something like "dummyEnemy" and then tag it with "Enemy." To create a tag, click the drop down for tag, click "add tag" and then where it says element0 if you haven't created any before, put Enemy here, and now it should show up. Change the tag to Enemy now and everything should work.
I looked at the demo scene that comes with it and it worked.
where to download the demo scene,as i am currently working on similar blips Can your help me .
$$anonymous$$y Question
(Detect sign on Fix $$anonymous$$ini map,When click on moving map,just like pin point) THX
Your answer
Follow this Question
Related Questions
A node in a childnode? 1 Answer
Help with minimap 1 Answer
How to Create a Multi Floor Mini Map 1 Answer
Use kinect depth map as input? 1 Answer
how to implement mini map 2 Answers