Skip to content

Instantly share code, notes, and snippets.

@kihira
Created November 3, 2015 13:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kihira/ff71d99e27822b56a8dc to your computer and use it in GitHub Desktop.
Save kihira/ff71d99e27822b56a8dc to your computer and use it in GitHub Desktop.
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