Screen-space Canvas not showing up in game.
hey gang, everything is set up correctly and working, however in the scene you can see the healthbars, and everything seems to be working fine but for some reason in the Demode you cannot see anything that's non the screen canvas. Camera is on default game settings :)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class GUItacker : MonoBehaviour
{
public Image TrackIcon;
public GameObject TrackObj;
public GameObject MainCam;
public Camera MainCamCam;
public bool Visible;
// Update is called once per frame
void Update()
{
if (MainCam == null)
{
MainCam = GameObject.FindGameObjectWithTag("MainCamera");
MainCamCam = MainCam.GetComponent<Camera>();
}
if (Visible == true)
{
TrackObj.SetActive(true);
Vector3 namePos = MainCamCam.WorldToScreenPoint(this.transform.position);
TrackIcon.transform.position = namePos;
}
if (Visible == false)
{
TrackObj.SetActive(false);
}
}
void OnBecameVisible()
{
Visible = true;
TrackObj.SetActive(true);
}
void OnBecameInvisible()
{
Visible = false;
TrackObj.SetActive(false);
}
}
Comment
Your answer
Follow this Question
Related Questions
Assign main camera to a prefab with a canvas 0 Answers
Retain Position and Scale Values of Render Texture Canvas Elements to another Canvas 0 Answers
UI Elements repositioning and resizing when playing game 1 Answer
Sprite in Canvas not projected correctly in Maximum playmode 0 Answers
Camera as collider 2D 0 Answers