Created
September 5, 2015 03:58
-
-
Save OutlawGameTools/eac62e76f34a4239ee36 to your computer and use it in GitHub Desktop.
Used with DOTween to make message, scores, etc., float up (or down) and fade out.
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
using UnityEngine; | |
using System.Collections; | |
using UnityEngine.UI; | |
using DG.Tweening; | |
public class DriftingText : MonoBehaviour { | |
public GameObject canvas; | |
public GameObject textPrefab; | |
public float driftTime = 1f; | |
public float relativeYEndPos = 1.5f; | |
private Text msgTxt; | |
void Awake() | |
{ | |
if (canvas == null) | |
canvas = GameObject.Find("Canvas"); | |
} | |
public void MakeDriftingText (string msg, Vector2 pos) | |
{ | |
GameObject ptTxt = Instantiate(textPrefab) as GameObject; | |
msgTxt = ptTxt.GetComponent<Text>(); | |
ptTxt.transform.SetParent(canvas.transform, false); | |
ptTxt.transform.position = pos; | |
msgTxt.text = msg; | |
float endYPos = pos.y + relativeYEndPos; | |
ptTxt.transform.DOMoveY(endYPos, driftTime).SetEase(Ease.OutQuint); | |
msgTxt.DOFade(0f, driftTime); | |
Destroy(ptTxt, driftTime); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment