Hi guys i manged to make one way point that is attached to a target and it tells the distance between the target and the player
Now im trying to add 5 more and thats what i cant figure out. So im trying to make 6 way points with each target telling the player the distance between the player and target
This is my code
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Waypoint : MonoBehaviour
{
private Image iconImg;
private Text distanceText;
public Transform Player;
public Transform Target;
public Camera Camera;
public float closeDistance;
// Update is called once per frame
private void Start()
{
iconImg = GetComponent<Image>();
distanceText = GetComponentInChildren<Text>();
}
private void Update()
{
if(Target != null)
{
GetDistance();
CheckOnScreen();
}
}
private void GetDistance()
{
float dist = Vector3.Distance(Player.position, Target.position);
distanceText.text = dist.ToString("f1") + "m";
if(dist < closeDistance)
{
Destroy(gameObject);
}
}
private void CheckOnScreen()
{
float thing = Vector3.Dot((Target.position - Camera.transform.position).normalized, Camera.transform.forward);
if(thing <= 0)
{
ToggleUI(false);
}
else
{
ToggleUI(true);
transform.position = Camera.WorldToScreenPoint(Target.position);
}
}
private void ToggleUI(bool _value)
{
iconImg.enabled = _value;
distanceText.enabled = _value;
}
}
Thanks in advance