Batch 1 - Scripts
This commit is contained in:
46
Assets/New Lowpoly Models/Scripts/WorldMarker.cs
Normal file
46
Assets/New Lowpoly Models/Scripts/WorldMarker.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class WorldMarker : MonoBehaviour
|
||||
{
|
||||
[Header("References")]
|
||||
[SerializeField] private Transform target;
|
||||
[SerializeField] private TextMeshProUGUI distanceText;
|
||||
|
||||
private Camera cam;
|
||||
private Transform player;
|
||||
|
||||
void Start()
|
||||
{
|
||||
cam = Camera.main;
|
||||
|
||||
PlayerControllerNewRohan p = FindObjectOfType<PlayerControllerNewRohan>();
|
||||
if (p != null)
|
||||
player = p.transform;
|
||||
}
|
||||
|
||||
void LateUpdate()
|
||||
{
|
||||
if (cam == null)
|
||||
cam = Camera.main;
|
||||
|
||||
if (player == null)
|
||||
{
|
||||
PlayerControllerNewRohan p = FindObjectOfType<PlayerControllerNewRohan>();
|
||||
if (p != null)
|
||||
player = p.transform;
|
||||
}
|
||||
|
||||
if (cam == null || player == null)
|
||||
return;
|
||||
|
||||
// Billboard
|
||||
transform.forward = cam.transform.forward;
|
||||
|
||||
// Distance
|
||||
float distance = Vector3.Distance(player.position, target.position);
|
||||
|
||||
distanceText.text = $"{Mathf.RoundToInt(distance)}m";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user