Question by
Wesley21spelde · Mar 13, 2018 at 12:37 PM ·
not workinghealthbaradjusthealth
Healthbar system not working correctly
Hey guys im having a problem with the healthbar Scrollbar when my character recieves damage from a ai or bot the health bar gets cut at like 50% and it does not work on the health system correctly can you help me ?
This is the whole script but i still cant fix it
using UnityEngine; using System; using UnityStandardAssets.Utility; using System.Collections; using UnityEngine.UI;
public class EnemyHealthRPC : Photon.MonoBehaviour
{
public GameObject hitFlash;
public GameObject hitShield;
public AudioSource flagdrop;
public float health = 100f;
public float hitPoints = 10;
public AudioClip hitdamage;
public AudioClip dieSound;
public Transform MasterchiefRagdoll;
public Rigidbody deadReplacement;
public GameObject MasterchiefRagdollDestroy;
public Transform NM;
public Transform flag;// dit is een box voor als we de flag hebben.
public bool isDie = false;
public Scrollbar HealthBar;
void Awake()
{
MasterchiefRagdollDestroy.GetComponent<DestroyAther>().enabled = false;
hitFlash.SetActive(false);
hitShield.SetActive(false);
//HealthBar = HealthBar.transform.FindDeepChild("HealthBar");
}
void hitdamageSound()
{
AudioSource.PlayClipAtPoint(hitdamage, transform.position);
}
[PunRPC]
public void TakeHealth(float amount)
{
if (health <= 100)
{
hitdamageSound();
health += amount;
HealthBar.size += health;
}
if (health > 200f)
{
AudioSource.PlayClipAtPoint(dieSound, transform.position);
}
}
IEnumerator HealthFlash()
{
hitShield.SetActive(true);
hitFlash.SetActive(true);
print(Time.time);
yield return new WaitForSeconds(2);
print(Time.time);
hitFlash.SetActive(false);
hitShield.SetActive(false);
}
[PunRPC]
public void TakeDamage (float amount)
{
hitdamageSound();
health -= amount;
HealthBar.size -= health;
AudioSource.PlayClipAtPoint(hitdamage, transform.position);
StartCoroutine(HealthFlash());
if (health <= 0f)
{
AudioSource.PlayClipAtPoint(dieSound, transform.position);
Die();
}
}
void Die()
{
if (flag == null && transform.Find("Flag"))
{
flag = transform.Find("Flag");
AudioSource audio = GetComponent<AudioSource>();
audio.Play();
flag.transform.parent = null;
}
else
{
//do nothing.
}
//
if (MasterchiefRagdoll != null)
{
isDie = true;
//Transform NM = GameObject.FindWithTag("NetworkManager").transform;
//NM.SendMessage("IdidDie", 5.0F);
//MasterchiefRagdoll.parent = null;
Rigidbody clone;
clone = Instantiate(deadReplacement, transform.position, transform.rotation) as Rigidbody;
clone.velocity = transform.TransformDirection(Vector3.forward * 10);
//Destroy(this.photonView);
Destroy(gameObject);
PhotonNetwork.Destroy(gameObject);
}
else
{
//Transform NM = GameObject.FindWithTag("NetworkManager").transform;
//NM.SendMessage("IdidDie", 5.0F);
Destroy(this.photonView);
Destroy(gameObject);
PhotonNetwork.Destroy(gameObject);
}
}
}
i do think its this part thats wrong . HealthBar.size -= health;
by the way i do know that i have sounds like die sound for multiple functions but i will change that later in the game
Comment