Transform WorldSpace Position in screen space?

So the problem is the following: I have auto generated a maze and now try to add a map so that the player can see where he/she currently is. My problem is that I dont know how to manage to align my ui elements that they resemble my maze.

Here is my code till now:

using UnityEngine;
using UnityEngine.UI;

public class ShowMaze : MonoBehaviour
{
    public Image RoomPrefab;
    public GameObject Player;
    public GameObject[] Rooms;
   
    bool instantiated = false;
   
    void CreateRooms()
    {
        foreach(GameObject Room in Rooms)
        {
            var room = Instantiate(RoomPrefab, transform.position, Quaternion.identity);
            room.transform.parent = this.transform;
        }
    }
   
    IEnumerator TestIfInstantiate(GameObject[] tempAry, float waitTime)
    {
        int oldLength = tempAry.Length;
       
        yield return new WaitForSeconds(waitTime);
       
        int length = tempAry.Length;
       
        if(length == oldLength && !instantiated)
        {
            instantiated = true;
            CreateRooms();
        }
    }

    void Update()
    {
        Rooms = GameObject.FindGameObjectsWithTag("Room");
       
        StartCoroutine(TestIfInstantiate(Rooms, 1));
    }
}

Just use a second camera which only renders the layers you want for your map.

Although first, I suggest fixing the code you provided for creating your rooms. You certainly should not be calling find objects with tag every frame and nor should you be starting a new coroutine every frame.

1 Like