Health Update
BIN
Assets/Prefabs/Health Pickup.prefab
Normal file
@ -28,11 +28,14 @@ public class PlayerHealth : MonoBehaviour
|
||||
anim = GetComponent <Animator> ();
|
||||
playerAudio = GetComponent <AudioSource> ();
|
||||
playerController = GetComponent <PlayerController> ();
|
||||
//playerShooting = GetComponentInChildren <PlayerShooting> ();
|
||||
|
||||
// Set the initial health of the player.
|
||||
currentHealth = startingHealth;
|
||||
}
|
||||
//playerShooting = GetComponentInChildren <PlayerShooting> ();
|
||||
healthSlider = GameObject.FindGameObjectWithTag("HealthSlider").GetComponent<Slider>();
|
||||
|
||||
|
||||
// Set the initial health of the player.
|
||||
currentHealth = startingHealth;
|
||||
|
||||
}
|
||||
|
||||
|
||||
void Update ()
|
||||
@ -42,14 +45,17 @@ public class PlayerHealth : MonoBehaviour
|
||||
}
|
||||
|
||||
|
||||
void OnTriggerEnter(Collider other)
|
||||
void OnTriggerEnter2D(Collider2D other)
|
||||
{
|
||||
if (other.gameObject.CompareTag("HealthPickup"))
|
||||
{
|
||||
Debug.Log("Health Pickup");
|
||||
currentHealth = currentHealth + healthToRecoverOnPickup;
|
||||
if (currentHealth > startingHealth)
|
||||
{
|
||||
currentHealth = startingHealth;
|
||||
}
|
||||
healthSlider.value = currentHealth;
|
||||
Destroy(other);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
BIN
Assets/Spritesheets/Health Pickup Spritesheet.png
Normal file
|
After Width: | Height: | Size: 23 KiB |
|
Before Width: | Height: | Size: 8.4 KiB After Width: | Height: | Size: 8.4 KiB |
|
Before Width: | Height: | Size: 17 KiB After Width: | Height: | Size: 17 KiB |
|
Before Width: | Height: | Size: 2.2 KiB After Width: | Height: | Size: 2.2 KiB |