| | |
| | | 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; |
| | | randomStartingPointX = UnityEngine.Random.value - 0.5f; |
| | | randomStartingPointY = UnityEngine.Random.value * 15f; |
| | | textTransform.position = new Vector3(textTransform.position.x, textTransform.position.y + randomStartingPointY, textTransform.position.y); |
| | | } |
| | | |
| | | private void Update() |
| | | { |
| | | timeElapsed += Time.deltaTime; |
| | | float deltaTime = Time.deltaTime; |
| | | if (timeElapsed >= startToFade) |
| | | { |
| | | // start fading when "startToFade" time is reached |
| | |
| | | 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)); |
| | | textTransform.position = new Vector3(startingPosition.x + (Mathf.Sin(phase) * moveSpeed.x), textTransform.position.y + (moveSpeed.y * deltaTime), textTransform.position.z + (moveSpeed.z * deltaTime)); |
| | | |
| | | } |
| | | } |