Advertisement
kasru

Scrolling Combat Text

Jan 18th, 2013
2,396
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //****** Donations are greatly appreciated.  ******
  2. //****** You can donate directly to Jesse through paypal at  https://www.paypal.me/JEtzler  ******
  3.  
  4. //----------------------------------------------------------------------
  5. //Main Combat Text Script
  6. //----------------------------------------------------------------------
  7.  
  8.  
  9. private var scroll: float = 0.08; // scrolling velocity private var duration: float = 1.5; // time to die private var alpha: float;
  10. private var alpha : float = 4.00;
  11. private var duration : float = 1.50;
  12.  
  13. function Start(){
  14.  
  15.     guiText.material.color = Color(1,1,1,1.0);
  16.     alpha = 1;
  17. }
  18.  
  19. function Update(){
  20.  
  21.     if (alpha>0){
  22.             transform.position.y += scroll*Time.deltaTime;
  23.             alpha -= Time.deltaTime/duration;
  24.             guiText.material.color.a = alpha;  
  25.  
  26.     }
  27.     else {
  28.         Destroy(transform.gameObject);
  29.     }
  30. }
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38. //----------------------------------------------------------------------
  39. //Other script to call combat text
  40. //----------------------------------------------------------------------
  41.  
  42. var ptsPrefab: Transform; // drag the prefab to this variable in Inspector
  43.  
  44. function spawnPts(points: float, x: float, y: float){
  45.     x = Mathf.Clamp(x,0.05,0.95); // clamp position to screen to ensure
  46.     y = Mathf.Clamp(y,0.05,0.9);  // the string will be visible
  47.     var gui: Transform = Instantiate(ptsPrefab,Vector3(x,y,0),Quaternion.identity);
  48.     gui.guiText.text = points.ToString();
  49.     gui.guiText.material.color = Color(1,1,1,1.0);
  50.      
  51. }
  52.  
  53.  
  54.  
  55. //----------------------------------------------------------------------
  56. //last piece of code to call function
  57. //----------------------------------------------------------------------
  58.  
  59. spawnPts(100,0.3,0.4);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement