- Home /
 
 
               Question by 
               dandelo99 · Jan 16, 2016 at 09:26 PM · 
                javascripthealthbar  
              
 
              Healthbar in js
hello everyone i have PlayerStats.js i tried to find add healthbar but i found always .cs type can someone help me how can i add healthbar it basicly i know creating canvas and healthbar, background images this is my script
 #pragma strict
 
 var MaxHealth = 100;
 var Health : int;
 
 function Start ()
 {
     Health = MaxHealth;
 }
 
 function ApplyDamage (TheDamage : int)
 {
     if(Health >= 0)
     {
         Health -= TheDamage;
     }
     if(Health <= 0)
     {
         Dead();
     }
 }
 
 function Dead()
 {
     RespawnMenuV2.playerIsDead = true; 
     Debug.Log("Player Died");
 }
 
 function RespawnStats ()
 {
     Health = MaxHealth;
 }
 
              
               Comment
              
 
               
              this is the cs
 public float max_health = 100f;
 public float cur_health=0f;
 public GameObject healthBar;
  
 
 void Start()
 {
     cur_health = max_health;
     InvokeRepeating("decrasehealth" , 1f,1f);
 }
 
 
 void decrasehealth ()
 {
     cur_health -= 2f;
     float calc_health = cur_health / max_health; // if cur health 80 / max_health (100) = 0.8f
     SetHealthBar (calc_health);
 }
 
 public void SetHealthBar(float myHealth)
 {
     //myHealth needs to be value between 0 and 0.1 ,
     healthBar.tarnsform.localScale = new Vector3( myHealth,healthBar.transform.localScale.y ,healthBar.transform.localScale.z)
 }
                 Your answer
 
             Follow this Question
Related Questions
How Do I Make A Health Bar 6 Answers
Health Bar 0 Answers
Setting Scroll View Width GUILayout 1 Answer
My healtbar is not change when i look another enemy 0 Answers
C# to Java UI Health Bar 1 Answer