Advertisement
irishstorm

_Globallogic

Oct 17th, 2012
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //_Globallogic.js
  2. //  Author : Christopher Cullen
  3. //  Date : 17/10/2012
  4.  
  5. /*  Health variablea    */
  6. var health : int = 100;
  7.  
  8. /*  Health GUI variables    */
  9. var healthGUI : GUIStyle;
  10. var xPos : float = 1.20;
  11. var yPos : float = 1.13;
  12. var xScale : float = 5.60;
  13. var yScale : float = 10.0;
  14.  
  15. /*  Player variables    */
  16. var grounded : boolean = false;
  17. var fallDamage : int = 0;
  18. var maxJumpHeight : int = 64;
  19. var isTouching = 0;
  20.  
  21. /* Going to leave this here as a reminder.
  22. var X : float = 0;
  23. var Y : float = 0;
  24. var Z : float = 0;
  25. */
  26.  
  27. function Start ()
  28. {
  29.  
  30. }
  31.  
  32. function Update ()
  33. {
  34.     Health();
  35.     FallDamage();
  36. }
  37.  
  38. function Health()
  39. {
  40.     // Checks to see if health is less than 0, if it is Set health to zero and kill the player.
  41.     if(health <= 0 )
  42.     {
  43.         // So that the players health doesn't go past Zero.
  44.         health = 0;
  45.        
  46.         //Kill the player
  47.         //Destroy (player);
  48.     }
  49.    
  50.     //If the players health is more than 100 than set the players health to 100.
  51.     if(health > 100 )
  52.     {
  53.         // So that the players health doesn't go past 100.
  54.         health = 100;
  55.     }
  56.    
  57.     // If the players health is more than 75%, set the Colour to Green
  58.     if(health >= 75 )
  59.     {
  60.         healthGUI.normal.textColor = Color.green;
  61.     }
  62.    
  63.     // If the players health is less than 74% and more that 26%, set the colour to Orange.
  64.     if(health <= 74 && health >= 26 )
  65.     {
  66.         healthGUI.normal.textColor = Color( 0.96, 0.60, 0);
  67.         // Going to leave this here as a reminder. How i adjusted the colour.
  68.         //healthGUI.normal.textColor = Color( X, Y, Z);
  69.     }
  70.    
  71.     // If the players health is less than 25%, set the colour to Red.
  72.     if(health <= 25 )
  73.     {
  74.         healthGUI.normal.textColor = Color.red;
  75.     }
  76. }
  77.  
  78. function FallDamage()
  79. {
  80.     // If the the player is on the ground and falldamage is more that max jumpHeight
  81.     // take the fall damage from the players health.
  82.     if(grounded == true )
  83.     {
  84.         if(fallDamage > maxJumpHeight)
  85.         {
  86.             health -= fallDamage;
  87.             fallDamage = 0;
  88.         }
  89.         // If the fall damage is less than the maxJumpHeight then reset fall damage to zero.
  90.         else if(fallDamage < maxJumpHeight)
  91.         {
  92.             fallDamage = 0;
  93.         }
  94.     }
  95.     //Need away to make it so that it only runs when the axis is -Y.
  96.     if(grounded == false )
  97.     {
  98.         fallDamage++;
  99.         Debug.Log(fallDamage);
  100.     }
  101. }
  102.  
  103. function OnCollisionEnter()
  104. {
  105.     isTouching ++;
  106.    
  107.     if(isTouching >= 0)
  108.     {
  109.         grounded = true;
  110.     }
  111. }
  112.  
  113. function OnCollisionExit()
  114. {
  115.     isTouching--;
  116.    
  117.     if(isTouching <= 1)
  118.     {
  119.         grounded = false;
  120.         isTouching= 0;
  121.     }
  122. }
  123.  
  124. function OnGUI()
  125. {
  126.     // Creates the text on the screen.
  127.     GUI.Label(new Rect(Screen.width / xPos, Screen.height / yPos, Screen.width / xScale, Screen.height / yScale), "" + health + "%",healthGUI);
  128.    
  129. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement