Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// <summary>
- /// Controls the floating text behavior.
- /// </summary>
- public class FloatingText : NetworkBehaviour
- {
- /// <summary>
- /// The TextMeshPro component used to display the floating text.
- /// </summary>
- [SerializeField] private TextMeshPro floatingText;
- /// <summary>
- /// CountdownTimer fo
- /// </summary>
- private CountdownTimer _countdownTimer;
- /// <summary>
- /// The time after which the text will be destroyed.
- /// </summary>
- public float textDestroyTimer = 2f;
- /// <summary>
- /// The speed at which the text moves upwards.
- /// </summary>
- public float textSpeed = .01f;
- public override void OnStartNetwork()
- {
- base.OnStartNetwork();
- floatingText = GetComponent<TextMeshPro>();
- _countdownTimer = new CountdownTimer(textDestroyTimer);
- _countdownTimer.Start();
- }
- private void Update()
- {
- // Tick the timer if it isn't finished
- if (!_countdownTimer.IsFinished())
- {
- _countdownTimer.Tick(Time.deltaTime);
- }
- }
- /// <summary>
- /// Update is called once per frame.
- /// </summary>
- private void FixedUpdate()
- {
- transform.Translate(Vector2.up * (textSpeed * Time.deltaTime));
- if (_countdownTimer.IsFinished())
- {
- SpawnManager.Instance.RPC_DespawnObject(base.NetworkObject);
- }
- }
- /// <summary>
- /// Sets the text and color of the floating text.
- /// </summary>
- /// <param name="text">The text to display.</param>
- /// <param name="color">The color of the text.</param>
- [ServerRpc(RequireOwnership = false)]
- public void RPC_SetText(string text, Color color)
- {
- SetText(text, color);
- }
- [ObserversRpc]
- private void SetText(string text, Color color)
- {
- if (floatingText == null)
- {
- Debug.LogWarning("FloatingText component is not assigned.");
- return;
- }
- floatingText.text = text;
- floatingText.color = color;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment