Certainly, I'm happy to help! Below is a C# script for using with Unity and TextMeshPro that will implement the desired behavior:
A public TextMeshProUGUI text to show current world coordinates.
A public TextMeshProUGUI text to show distance to the closest destination point (or random point if damaged).
A public TextMeshProUGUI text to show a list of available points.
A public TextMeshProUGUI text to show current time of day.
A list of destination points, with each having a Transform.
A bool Damaged to determine if the detection should provide a random point.
Update the random point every 3-10 minutes if Damaged is true.
First, make sure you have the TextMeshPro package imported into your Unity project. Then, you can use the following script:
csharp Copy code
using System.Collections.Generic;
using UnityEngine;
using TMPro;
using System.Linq;
public class Detector : MonoBehaviour
{
public TextMeshProUGUI textCurrentCoordinates;
public TextMeshProUGUI textDistanceToDestination;
public TextMeshProUGUI textListOfPoints;
public TextMeshProUGUI textTimeOfDay;
public List<Transform> destinationPoints;
private Transform closestOrRandomPoint;
private float distanceToPoint;
public bool Damaged = false;
private float nextChangeTime;
void Start()
{
UpdateListOfPoints();
ChooseRandomPoint();
}
void Update()
{
UpdateCurrentCoordinates();
UpdateTimeOfDay();
UpdateDistanceToPoint();
}
void UpdateCurrentCoordinates()
{
Vector3 playerPos = transform.position;
textCurrentCoordinates.text = $"Coordinates: ({playerPos.x}, {playerPos.y}, {playerPos.z})";
}
void UpdateDistanceToPoint()
{
if (Damaged && Time.time > nextChangeTime)
{
ChooseRandomPoint();
}
closestOrRandomPoint = Damaged ? closestOrRandomPoint : GetClosestPoint();
distanceToPoint = Vector3.Distance(transform.position, closestOrRandomPoint.position);
textDistanceToDestination.text = $"Distance to point: {distanceToPoint}";
}
Transform GetClosestPoint()
{
return destinationPoints.OrderBy(p => Vector3.Distance(transform.position, p.position)).First();
}
void ChooseRandomPoint()
{
if (destinationPoints.Count == 0) return;
closestOrRandomPoint = destinationPoints[Random.Range(0, destinationPoints.Count)];
nextChangeTime = Time.time + Random.Range(3 * 60, 10 * 60); // Random time between 3 to 10 minutes
}
void UpdateListOfPoints()
{
textListOfPoints.text = string.Join("\n", destinationPoints.Select((p, index) => $"{index + 1}: ({p.position.x}, {p.position.y}, {p.position.z})"));
}
void UpdateTimeOfDay()
{
System.DateTime currentTime = System.DateTime.Now;
textTimeOfDay.text = $"Time of Day: {currentTime:HH:mm:ss}";
}
}
Explanation:
TextMeshProUGUI Fields: Four fields to display world coordinates, distance to the point, the list of points, and the time of day.
List of DestinationPoints: A list of Transform references that represent your destination points.
Start Method: Initialize the list of points and choose a random point initially.
Update Method: Calls functions to update the displayed coordinates, time, and distance.
UpdateCurrentCoordinates: Extracts and displays the player's current coordinates.
UpdateDistanceToPoint: Manages the distance display, chooses a new random point if Damaged is true and if it is time to change the point.
GetClosestPoint: Finds the nearest destination point.
ChooseRandomPoint: Sets a random point and a timer for the next change.
UpdateListOfPoints: Creates a newline-separated list of destination points.
UpdateTimeOfDay: Displays the current time in HH:mm:ss format.
Attach this script to a GameObject, set its public fields accordingly in the Unity Editor and it should function as described.