Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //_Globallogic.js
- // Author : Christopher Cullen
- // Date : 17/10/2012
- /* Health variablea */
- var health : int = 100;
- /* Health GUI variables */
- var healthGUI : GUIStyle;
- var xPos : float = 1.20;
- var yPos : float = 1.13;
- var xScale : float = 5.60;
- var yScale : float = 10.0;
- /* Player variables */
- var grounded : boolean = false;
- var fallDamage : int = 0;
- var maxJumpHeight : int = 64;
- var isTouching = 0;
- /* Going to leave this here as a reminder.
- var X : float = 0;
- var Y : float = 0;
- var Z : float = 0;
- */
- function Start ()
- {
- }
- function Update ()
- {
- Health();
- FallDamage();
- }
- function Health()
- {
- // Checks to see if health is less than 0, if it is Set health to zero and kill the player.
- if(health <= 0 )
- {
- // So that the players health doesn't go past Zero.
- health = 0;
- //Kill the player
- //Destroy (player);
- }
- //If the players health is more than 100 than set the players health to 100.
- if(health > 100 )
- {
- // So that the players health doesn't go past 100.
- health = 100;
- }
- // If the players health is more than 75%, set the Colour to Green
- if(health >= 75 )
- {
- healthGUI.normal.textColor = Color.green;
- }
- // If the players health is less than 74% and more that 26%, set the colour to Orange.
- if(health <= 74 && health >= 26 )
- {
- healthGUI.normal.textColor = Color( 0.96, 0.60, 0);
- // Going to leave this here as a reminder. How i adjusted the colour.
- //healthGUI.normal.textColor = Color( X, Y, Z);
- }
- // If the players health is less than 25%, set the colour to Red.
- if(health <= 25 )
- {
- healthGUI.normal.textColor = Color.red;
- }
- }
- function FallDamage()
- {
- // If the the player is on the ground and falldamage is more that max jumpHeight
- // take the fall damage from the players health.
- if(grounded == true )
- {
- if(fallDamage > maxJumpHeight)
- {
- health -= fallDamage;
- fallDamage = 0;
- }
- // If the fall damage is less than the maxJumpHeight then reset fall damage to zero.
- else if(fallDamage < maxJumpHeight)
- {
- fallDamage = 0;
- }
- }
- //Need away to make it so that it only runs when the axis is -Y.
- if(grounded == false )
- {
- fallDamage++;
- Debug.Log(fallDamage);
- }
- }
- function OnCollisionEnter()
- {
- isTouching ++;
- if(isTouching >= 0)
- {
- grounded = true;
- }
- }
- function OnCollisionExit()
- {
- isTouching--;
- if(isTouching <= 1)
- {
- grounded = false;
- isTouching= 0;
- }
- }
- function OnGUI()
- {
- // Creates the text on the screen.
- GUI.Label(new Rect(Screen.width / xPos, Screen.height / yPos, Screen.width / xScale, Screen.height / yScale), "" + health + "%",healthGUI);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement