From eab47305629d96d19626e10b649ba4247d1f55f5 Mon Sep 17 00:00:00 2001
From: miepzerino <o.skotnik@gmail.com>
Date: Sat, 23 Dec 2023 21:20:31 +0000
Subject: [PATCH] Added loading screen, moved tilemap generation to coroutine
---
Assets/Scripts/HealthText.cs | 27 +++++++++++++++++++++++----
1 files changed, 23 insertions(+), 4 deletions(-)
diff --git a/Assets/Scripts/HealthText.cs b/Assets/Scripts/HealthText.cs
index 2f8907c..f68a692 100644
--- a/Assets/Scripts/HealthText.cs
+++ b/Assets/Scripts/HealthText.cs
@@ -6,20 +6,31 @@
public class HealthText : MonoBehaviour
{
- public Vector3 moveSpeed = new Vector3(0, 75, 0);
-
+ // x = oscillation amount (0 = no oscillation), y = upwards speed
+ public Vector3 moveSpeed = new Vector3(25f, 75, 0);
+ // oscillation speed
+ public float oscillationsPerSecond = 1.0f;
+ // x of seconds it takes to fade away
public float timeToFade = 1f;
+ // start fading after x seconds
public float startToFade = 1f;
private float timeElapsed = 0f;
+ private float randomStartingPointX;
+ private float randomStartingPointY;
+ private Vector3 startingPosition;
RectTransform textTransform;
-
TextMeshProUGUI textMeshPro;
private void Awake()
{
textTransform = GetComponent<RectTransform>();
textMeshPro = GetComponent<TextMeshProUGUI>();
+ startingPosition = textTransform.position;
+ // add random starting position for text
+ randomStartingPointX = (float)new System.Random().NextDouble() - 0.5f;
+ randomStartingPointY = (float)new System.Random().NextDouble() * 15f;
+ textTransform.position = new Vector3(textTransform.position.x, textTransform.position.y + randomStartingPointY, textTransform.position.y);
}
private void Update()
@@ -27,12 +38,20 @@
timeElapsed += Time.deltaTime;
if (timeElapsed >= startToFade)
{
+ // start fading when "startToFade" time is reached
textMeshPro.alpha = (1 - ((timeElapsed - startToFade) / timeToFade));
if (timeElapsed >= (startToFade + timeToFade))
{
+ // destroy object when end of live is reached
Destroy(gameObject);
}
}
- textTransform.position += moveSpeed * Time.deltaTime;
+
+ // calc oscillation phase
+ float phase = ((randomStartingPointX + timeElapsed) * oscillationsPerSecond * (2f * Mathf.PI));
+
+ // set new position of object
+ textTransform.position = new Vector3(startingPosition.x + (Mathf.Sin(phase) * moveSpeed.x), textTransform.position.y + (moveSpeed.y * Time.deltaTime), textTransform.position.z + (moveSpeed.z * Time.deltaTime));
+
}
}
--
Gitblit v1.10.0