#So I am having another problem with UI

1 messages · Page 1 of 1 (latest)

elfin vigil
#

Code not in embed.

using UnityEngine.UI;
public class Waypoints : MonoBehaviour
{
    public Image MarkerImage; //The image to use
    public Canvas HUD; //Our Canvas to set waypoint as child to so it actually shows on camera
    public List<Image> Markers; //A list to hold markers
    public List<GameObject> Targets; //A list to hold all targets

//Start removed due to word count, basically for all enemies we add a marker image.

    void Update() //Yes this probably should be onGUI, but they pretty much do the same thing in this case.
    {
        foreach (GameObject T in Targets)
        {
            MarkerLocation(T, Targets.IndexOf(T)); //We send the Index of every marker to MarkerLocation function, yes this is not best practice but it works for proof of concept.
        }
    }

    public void MarkerLocation(GameObject TargetLocation, int TargetListPos)
    {
        foreach (Image M in Markers) 
        {
            if ( Markers.IndexOf(M) == TargetListPos) //We check to make sure both Index locations match in their lists, meaning we can have multiple markers.
            {
                Debug.Log("Target " + TargetListPos + " is at: " + TargetLocation.transform.position);
                Debug.Log("Marker " + Markers.IndexOf(M) + " is at: " + Camera.main.WorldToScreenPoint(TargetLocation.transform.position));
                M.transform.position = Camera.main.WorldToScreenPoint(TargetLocation.transform.position); //<<<<<<< HERE WE ATTEMPT TO SET THE MARKERS LOCATION TO TARGET LOCATION IN SCREEN SPACE.
            }
        }
    }
}
#

Image highlighting issue (please note the marker is a place holder image)

#

Camera settings