Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
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
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

130 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

GUI Texture slide down || Clipping mask. 0 Answers

does someone have a player health script and a way to make a health bar? 0 Answers

health script not working 0 Answers

If detection not working quite as expected. 1 Answer

How to create a link between HealthScript and HealtBar script ? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges