Last active
August 28, 2015 19:16
-
-
Save gluschenko/9c538bb2b0627f71b05b to your computer and use it in GitHub Desktop.
This file contains hidden or 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 System.Collections.Generic; | |
public class ComboText : MonoBehaviour { | |
public static List<ComboEntry> Entries = new List<ComboEntry>(); | |
public float Speed = 10; | |
public static float Offset = 90; | |
public static void AddEntry(int Number, Vector2 ScreenPos) | |
{ | |
Entries.Add(new ComboEntry(Number, ScreenPos)); | |
} | |
public static void AddEntry(int Number, Transform Target) | |
{ | |
Vector2 Pos = Camera.main.WorldToScreenPoint(Target.position); | |
AddEntry(Number, new Vector2(Pos.x, Screen.height - Pos.y)); | |
} | |
void Start () | |
{ | |
} | |
void Update () | |
{ | |
List<ComboEntry> EntriesToDelete = new List<ComboEntry>(); | |
foreach(ComboEntry C in Entries) | |
{ | |
C.Lifetime -= Time.deltaTime; | |
C.ScreenPos = Vector2.Lerp(C.ScreenPos, C.EndPos, Time.deltaTime * Speed); | |
//C.ScreenPos = new Vector2(C.ScreenPos.x, C.ScreenPos.y - (Time.deltaTime * Speed)); | |
if(C.Lifetime < 0f) | |
{ | |
EntriesToDelete.Add (C); | |
} | |
} | |
foreach(ComboEntry C in EntriesToDelete) | |
{ | |
Entries.Remove(C); | |
//C = null; | |
} | |
} | |
void OnGUI() | |
{ | |
foreach(ComboEntry C in Entries) | |
{ | |
GUI.Label(new Rect(C.ScreenPos.x, C.ScreenPos.y, 50, 50), C.Number + ""); | |
} | |
} | |
} | |
public class ComboEntry | |
{ | |
public int Number; | |
public float Lifetime; | |
public Vector2 ScreenPos; | |
public Vector2 EndPos; | |
public ComboEntry(int _Number, Vector2 _ScreenPos, float _Lifetime = 1f) | |
{ | |
Number = _Number; | |
ScreenPos = _ScreenPos; | |
EndPos = new Vector2(_ScreenPos.x, _ScreenPos.y - ComboText.Offset); | |
Lifetime = _Lifetime; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment