Question by
Various69 · Feb 26, 2016 at 08:13 PM ·
scripting problem
HP, DMG, HUD scripts problem
Hello. I have 3 scripts
1. enemyhealth ( player health and npc-zombie health )
using UnityEngine;
using System.Collections;
public class enemyhealth : MonoBehaviour
{
public int health = 100;
public virtual void otrzymaneObrazenia(float damage)
{
if (health > 0)
{
health -= (int)damage;
if (health < 0)
{
health = 0;
}
}
}
}
2. enemydamage only for zombie hand damage
using UnityEngine;
public class enemydamage : MonoBehaviour
{
public float damage = 10.0f;
void OnTriggerEnter(Collider Enemy)
{
if (Enemy.gameObject.CompareTag("enemy"))
{
Enemy.gameObject.SendMessage("OnDamage", damage);
}
}
}
3. And last script for player hud
using UnityEngine;
using UnityEngine.UI;
public class ZdrowieGracza : enemyhealth {
public Text zdrowieUI;
public Image obrazeniaImage;
private float predkoscBlysku = 5f;
private Color kolorObrazenia = new Color (1f, 0f, 0f, 0.1f);
protected bool zadanoObrazenia = false;
public override void otrzymaneObrazenia(float damage) {
base.otrzymaneObrazenia(damage);
zadanoObrazenia = true;
}
void Update(){
if (zadanoObrazenia && obrazeniaImage != null) {
obrazeniaImage.color = kolorObrazenia;
zadanoObrazenia = false;
setZdrowieUI();
} else if(obrazeniaImage != null){
obrazeniaImage.color = Color.Lerp(obrazeniaImage.color, Color.clear, predkoscBlysku * Time.deltaTime);
}
}
private void setZdrowieUI(){
if (zdrowieUI != null);
}
}
Script is written in 2 languages (im sorry) but still my question is: where is mistake? When zombie attack player nothink happens with hp text. Maybe someone can help me?
Thanks in adwance.
Comment
Your answer
Follow this Question
Related Questions
Why is It not casting any Ray? [Scripting Problem] 0 Answers
Transforming standardassets into multiplayer 0 Answers
If Statement & checking current scene. 1 Answer
Vuforia: occlude image target? 1 Answer
Setting Velocities through Input 1 Answer