Dong_Minh_Doxygen: D:/Google Drive/Unity Projects/Tank Game/Assets/Scripts/Health.cs Source File

Dong Minh

Dong_Minh_Doxygen
Health.cs
Go to the documentation of this file.
1 using UnityEngine;
2 using UnityEngine.UI;
3 using System.Collections;
4 using UnityEngine.SceneManagement;
5 
6 public class Health : MonoBehaviour
7 {
8  public const int maxHealth = 20;
9  public int currentHealth = maxHealth;
10  public RectTransform healthbar;
11 
12 
13  [SerializeField]
14  private float fillAmount;
15 
16  [SerializeField]
17  private Image Content;
18 
24  void Update(){
25  HandleBar ();
26  }
27 
35  private void HandleBar(){
36  Content.fillAmount = Map(currentHealth, 0, maxHealth, 0, 1);
37  }
38 
46  private float Map(float value, float inMin, float inMax, float outMin, float outMax)
47  {
48  return (value - inMin) * (outMax - outMin) / (inMax - inMin) + outMin;
49  }
50 
61  public void TakeDamage(int amount)
62  {
63  currentHealth -= amount;
64  if (currentHealth <= 0)
65  {
66  currentHealth = 0;
67  Debug.Log("Dead!");
68  //Destroy(GameObject.FindGameObjectWithTag("tankObject"));
69  SceneManager.LoadScene (SceneManager.GetActiveScene ().name);
70  }
71 
72  //healthbar.sizeDelta = new Vector2 (currentHealth, healthbar.sizeDelta.y);
73  }// end take damage function
74 
75 
76 }
Definition: Health.cs:6
int currentHealth
Definition: Health.cs:9
void HandleBar()
Will get the fill amount for the health bar to determine its mapping and will update accordingly ...
Definition: Health.cs:35
void TakeDamage(int amount)
Whenever the player takes damage, the health will go down.
Definition: Health.cs:61
const int maxHealth
Definition: Health.cs:8
void Update()
Update once per frame to update the HandleBar
Definition: Health.cs:24
RectTransform healthbar
Definition: Health.cs:10
float fillAmount
Definition: Health.cs:14
Image Content
Definition: Health.cs:17
float Map(float value, float inMin, float inMax, float outMin, float outMax)
Calculations to determine the 0 to 1 Unity asset and will calculate if it is greater than 1...
Definition: Health.cs:46
Generated by   doxygen 1.8.13