Commit 72cfff97 by Alisa Jung

added playerHealth

parent 4739840b
using UnityEngine;
using System.Collections;
public class PlayerHealth : MonoBehaviour {
public int maxHealth = 100;
public int currentHealth = 100;
private bool alive = true;
// Update is called once per frame
void Update () {
if (alive && currentHealth <= 0)
{
Debug.Log("Player " + name + " dead.");
}
}
public int getCurrentHealth()
{
return currentHealth;
}
/// <summary>
/// Setzt Gesundheit auf bestimmten Wert, aber nicht mehr als maxHealth von dem Player.
/// </summary>
/// <param name="newHealth"></param>
public void setHealth(int newHealth)
{
currentHealth = (newHealth > maxHealth) ? maxHealth : newHealth;
}
/// <summary>
/// Erhöht bzw. erniedrigt aktuelle Gesundheit um Wert h, Gesundheit kann nicht höher werden als maxHealth.
/// </summary>
/// <param name="h"></param>
public void changeHealthBy(int h)
{
currentHealth += h;
if (currentHealth > maxHealth) currentHealth = maxHealth;
}
}
fileFormatVersion: 2
guid: 64eedc6579a413545b11c63c47c39d53
timeCreated: 1433439187
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment