- Home /
Minimap help
Hi, i wrote this code to create a minimap :)
void OnGUI () {
Handles.DrawCamera (new Rect (5, 5, 105, 105), this.gameObject.camera, DrawCameraMode.Normal);
}
It works, but i don't know how can I put a green circle on my player and ones red on the enemy..
Someone can help me ? :) Thank you :)
Answer by MakakWasTaken · Mar 29, 2015 at 07:16 PM
That depends on, whether or not the player is in the middle of the minimap, if he is it is easy:
public Texture2D marker;
void OnGUI() {
Handles.DrawCamera (new Rect (5, 5, 105, 105),camera, DrawCameraMode.Normal);
GUI.DrawTexture(new Rect(55,55,marker.width,marker.height),marker);
}
if not then you will have to get the normalposition of the player this depends on how much space the camera is covering in worldspace. If it draws the whole terrain then:
public Texture2D marker;
void OnGUI() {
Handles.DrawCamera (new Rect (5, 5, 105, 105),camera, DrawCameraMode.Normal);
GUI.DrawTexture(new Rect(5+minimapPosX,5+minimapPosY,marker.width,marker.height),marker);
}
void Update() {
minimapPosX = (transform.position.x/Terrain.activeTerrain.terrainData.size.x)*100;
minimapPosY = (transform.position.x/Terrain.activeTerrain.terrainData.size.z)*100;
}
For the enemies you could do this:
//Remember using System.Collections.Generic;
public Texture2D enemyMarker;
public Texture2D marker;
List<Vector2> enemyPos;
void OnGUI() {
Handles.DrawCamera (new Rect (5, 5, 105, 105),camera, DrawCameraMode.Normal);
GUI.DrawTexture(new Rect(5+Vector3ToMap(transform.position).x,5+Vector3ToMap(transform.position).y,marker.width,marker.height),marker);
foreach (Vector2 Pos in enemyPos) {
GUI.DrawTexture(new Rect(5+Pos.x,5+Pos.y,enemyMarker.width,enemyMarker.height), enemyMarker);
}
}
void Update() {
enemyPos.Clear(); //This might be .clear instead, I do not remember
foreach (GameObject enemy in GameObject.FindGameObjectsWithTag("Enemy")) {
enemyPos.Add(Vector3ToMap(enemy.transform.position));
}
}
Vector2 Vector3ToMap(Vector3 pos) {
Vector2 ret = Vector2.zero;
ret.x = (pos.x/Terrain.activeTerrain.terrainData.size.x)*100;
ret.y = (pos.z/Terrain.activeTerrain.terrainData.size.z)*100;
return ret;
}
Your answer
Follow this Question
Related Questions
Releasing render texture that is set to be RenderTexture.active! (error on android only) 0 Answers
Uncover mini/world map 0 Answers
How to create a dynamic map in hand of FPS like Far Cry 2 or Firewatch? 0 Answers
Assigning UV Map to model at runtime 0 Answers
How to make a minimap by pixels without second camera 1 Answer