-
-
Save kihira/ff71d99e27822b56a8dc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public Vector2 targetPos; | |
public float moveSpeed = 10; // How fast the text scrolls up | |
public float fadeOutTime = 2; // When to start fading out | |
private float timeRemaining; | |
void Start () | |
{ | |
timeRemaining = fadeOutTime; | |
} | |
void Update () | |
{ | |
// Move text up the screen | |
Vector2 pos = GetComponent<RectTransform>().anchoredPosition; | |
if (pos.y < targetPos.y) | |
{ | |
GetComponent<RectTransform>().anchoredPosition = new Vector2(pos.x, pos.y + (float)(moveSpeed * Time.deltaTime)); | |
} | |
// Begin fading out as we get near the end | |
if (targetPos.y - pos.y < fadeOutTime * moveSpeed) | |
{ | |
timeRemaining -= Time.deltaTime; | |
// Fade out | |
Color color = gameObject.GetComponent<Text>().color; | |
color.a = ((timeRemaining / fadeOutTime) * 2); | |
gameObject.GetComponent<Text>().color = color; | |
} | |
if (timeRemaining <= 0) | |
{ | |
Destroy(gameObject); | |
} | |
} | |
void OnDestroy() | |
{ | |
GameObject.Find("Score").GetComponent<ScoreManager>().RemoveScoreInfo(gameObject); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment