Health Update
BIN
Assets/Prefabs/Health Pickup.prefab
Normal file
@ -29,9 +29,12 @@ public class PlayerHealth : MonoBehaviour
|
|||||||
playerAudio = GetComponent <AudioSource> ();
|
playerAudio = GetComponent <AudioSource> ();
|
||||||
playerController = GetComponent <PlayerController> ();
|
playerController = GetComponent <PlayerController> ();
|
||||||
//playerShooting = GetComponentInChildren <PlayerShooting> ();
|
//playerShooting = GetComponentInChildren <PlayerShooting> ();
|
||||||
|
healthSlider = GameObject.FindGameObjectWithTag("HealthSlider").GetComponent<Slider>();
|
||||||
|
|
||||||
|
|
||||||
// Set the initial health of the player.
|
// Set the initial health of the player.
|
||||||
currentHealth = startingHealth;
|
currentHealth = startingHealth;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -42,14 +45,17 @@ public class PlayerHealth : MonoBehaviour
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void OnTriggerEnter(Collider other)
|
void OnTriggerEnter2D(Collider2D other)
|
||||||
{
|
{
|
||||||
if (other.gameObject.CompareTag("HealthPickup"))
|
if (other.gameObject.CompareTag("HealthPickup"))
|
||||||
{
|
{
|
||||||
Debug.Log("Health Pickup");
|
Debug.Log("Health Pickup");
|
||||||
currentHealth = currentHealth + healthToRecoverOnPickup;
|
currentHealth = currentHealth + healthToRecoverOnPickup;
|
||||||
|
if (currentHealth > startingHealth)
|
||||||
|
{
|
||||||
|
currentHealth = startingHealth;
|
||||||
|
}
|
||||||
healthSlider.value = currentHealth;
|
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 |