Commit d9140ec0 by Tim Reiter

healthbar implemented (for player one)

parent b03c8955
fileFormatVersion: 2 fileFormatVersion: 2
guid: 5fcd7bbd646a82a4b9e4aa5229a903e3 guid: 5fcd7bbd646a82a4b9e4aa5229a903e3
timeCreated: 1433444182 timeCreated: 1433446182
licenseType: Free licenseType: Free
NativeFormatImporter: NativeFormatImporter:
userData: userData:
......
fileFormatVersion: 2
guid: e0d90fce50c24884c8d83b9d365a5fe3
timeCreated: 1433446163
licenseType: Free
NativeFormatImporter:
userData:
assetBundleName:
assetBundleVariant:
using UnityEngine; using UnityEngine;
using System.Collections; using System.Collections;
using UnityEngine.UI;
public class PlayerHealth : MonoBehaviour { public class PlayerHealth : MonoBehaviour {
...@@ -7,6 +8,7 @@ public class PlayerHealth : MonoBehaviour { ...@@ -7,6 +8,7 @@ public class PlayerHealth : MonoBehaviour {
public int currentHealth = 100; public int currentHealth = 100;
private bool alive = true; private bool alive = true;
public Scrollbar healthbar;
// Update is called once per frame // Update is called once per frame
...@@ -29,6 +31,16 @@ public class PlayerHealth : MonoBehaviour { ...@@ -29,6 +31,16 @@ public class PlayerHealth : MonoBehaviour {
public void setHealth(int newHealth) public void setHealth(int newHealth)
{ {
currentHealth = (newHealth > maxHealth) ? maxHealth : newHealth; currentHealth = (newHealth > maxHealth) ? maxHealth : newHealth;
updateHealthbar();
}
//updated die ui healthbar.
private void updateHealthbar()
{
if (healthbar)
{
healthbar.size = (float)currentHealth / (float)maxHealth;
}
} }
/// <summary> /// <summary>
...@@ -39,6 +51,7 @@ public class PlayerHealth : MonoBehaviour { ...@@ -39,6 +51,7 @@ public class PlayerHealth : MonoBehaviour {
{ {
currentHealth += h; currentHealth += h;
if (currentHealth > maxHealth) currentHealth = maxHealth; if (currentHealth > maxHealth) currentHealth = maxHealth;
updateHealthbar();
} }
} }
...@@ -7,8 +7,10 @@ public class Trap : MonoBehaviour { ...@@ -7,8 +7,10 @@ public class Trap : MonoBehaviour {
void OnTriggerEnter2D(Collider2D other) void OnTriggerEnter2D(Collider2D other)
{ {
Debug.Log("trigg");
if (other.tag == "Player") if (other.tag == "Player")
{ {
Debug.Log("player col");
other.GetComponent<PlayerHealth>().changeHealthBy(-damagePoints); other.GetComponent<PlayerHealth>().changeHealthBy(-damagePoints);
transform.position = new Vector2(50, 50);//TODO setze auf 1000 oder so, zur sicherheit. transform.position = new Vector2(50, 50);//TODO setze auf 1000 oder so, zur sicherheit.
} }
......
No preview for this file type
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