Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

Using Top-Down Cam and uGUI to create minimap

Discussion in 'UGUI & TextMesh Pro' started by programmrzinc, May 17, 2016.

  1. programmrzinc

    programmrzinc

    Joined:
    May 29, 2011
    Posts:
    79
    Hey community.

    I have a environment that I want to have a minimap, But I'm not sure how to go about this. I have a camera in the sky, pointing downwards, and a canvas in front of it, set to "Screen Space - Camera". I would like to have this camera display dynamic info, concerning the location of gameobjects in the scene, preferably with the Image uGUI components, but how do I go about having the respective images atop their real world location?

    Here is the setup I would like to use.

    https://gyazo.com/636424d9697722eaed065b085cad3151
     
  2. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148


    seems like a fairly well rounded tutorial. Note that approach doesn't require a top down "minimap" camera at all. One shortfall that that tutorial has is the "map" is a static texture, if you want you can setup an orthographic top down camera and render what it sees to a RawImage on the minimap's canvas. You can then limit what it is seeing using the cullingmask option to just pick certain layers in the scene.

    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using UnityEngine.UI;
    4. using System.Collections;
    5.  
    6. public class GetCameraTexture : MonoBehaviour
    7. {
    8.     public Camera miniMapCamera;
    9.     public RawImage targetImage;
    10.  
    11.  
    12.     void Start()
    13.     {
    14.      
    15. miniMapCamera.targetTexture = (RenderTexture)targetImage.texture;
    16.     }
    17. }
    18.  
    19.  
    edit: code super simplified :)
     
    Last edited: May 18, 2016
    programmrzinc likes this.
  3. programmrzinc

    programmrzinc

    Joined:
    May 29, 2011
    Posts:
    79
    One of the features of the minimap I wanted would be a "real life" feed, and I think the RenderTexture idea is perfect. Thank you very much