rabidus-test/Assets/Scripts/SpeedText.cs

31 lines
643 B
C#
Raw Normal View History

2023-07-24 16:38:13 +03:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SpeedText : MonoBehaviour
{
private ShipPathFollower _pathFollower;
private TMPro.TextMeshProUGUI _text;
private void Awake()
{
_pathFollower = FindObjectOfType<ShipPathFollower>();
_text = GetComponent<TMPro.TextMeshProUGUI>();
}
private void OnEnable()
{
_pathFollower.OnSpeedChange += UpdateText;
}
private void OnDisable()
{
_pathFollower.OnSpeedChange -= UpdateText;
}
private void UpdateText(float speed)
{
_text.SetText(speed.ToString());
}
}