| 1 | namespace Oculus.Platform.Samples.VrHoops |
| 2 | { |
| 3 | using UnityEngine; |
| 4 | using UnityEngine.UI; |
| 5 | using System.Collections; |
| 6 | |
| 7 | // helper script to render fading flytext above an object |
| 8 | public class FlyText : MonoBehaviour |
| 9 | { |
| 10 | // destory the gameobject after this many seconds |
| 11 | private const float LIFESPAN = 3.0f; |
| 12 | |
| 13 | // how far to move upwards per frame |
| 14 | private readonly Vector3 m_movePerFrame = 0.5f * Vector3.up; |
| 15 | |
| 16 | // actual destruction time |
| 17 | private float m_eol; |
| 18 | |
| 19 | void Start() |
| 20 | { |
| 21 | m_eol = Time.time + LIFESPAN; |
| 22 | GetComponent<Text>().CrossFadeColor(Color.black, LIFESPAN * 1.7f, false, true); |
| 23 | } |
| 24 | |
| 25 | void Update() |
| 26 | { |
| 27 | if (Time.time < m_eol) |
| 28 | { |
| 29 | transform.localPosition += m_movePerFrame; |
| 30 | } |
| 31 | else |
| 32 | { |
| 33 | Destroy(gameObject); |
| 34 | } |
| 35 | } |
| 36 | } |
| 37 | } |