Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by aled96 · Mar 29, 2015 at 06:58 PM · mapminimap

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 :)

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

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;
 }
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

21 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges