Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
avatar image
0
Question by Matt 5 · Jan 25, 2012 at 07:40 PM · guitexturescoreprogress-bar

Adding a score progress bar

I'm trying to make a progress bar that tracks the score each time an enemy is destroyed this is the code I used but didn't display a thing:

public void LeftStatusMeter ( Texture charImage , Texture bBarImage , Texture hBarImage) {

 //Place Back Bars
 GUI.Label(new Rect(40, 10, 272, 90), bBarImage );
     
     //Place Front Bars
 GUI.BeginGroup( new Rect(100, 10, 218 * (Scoring.m_score * 10.0f), 90) );
 GUI.Label( new Rect(100, 0, 272, 90), hBarImage );
 GUI.EndGroup();
     
     GUI.EndGroup();
 }


I need this to work in a bar texture I have all the textures I need just implementing them into the code so it appears and shows up on screen.

Here is the full code in case it helps

using UnityEngine; using System.Collections;

public class DamagableObject : MonoBehaviour {

 public bool m_Invincible = false;
 public float m_MaxHealth = 100f;
 public string m_LevelToLoad;
 
 [SerializeField]
 protected float m_Health = 100f;
 
 GUISkin scoreSkin;
 public DecayingObject m_DeathEffectPrefab;
 public DecayingObject m_RemainsPrefab;
 public string m_DeathAnimation;
 
 public Texture2D lbarImage;
 public Texture2D lhbar;
 
 
 
 /*public virtual float health
 {
     set
     {
         if (!m_Invincible ||  m_Health < value)
         {
             m_Health = value;
         }
         if (m_Health <= 0)
         {
             Death();
         }
         else if (m_Health > m_MaxHealth)
         {
             m_Health = m_MaxHealth;
         }
     }
     
     get
     {
         return m_Health;
     }
 }*/
 
 public virtual void DealDamage(float val, Vector3 pos, Vector3 normal)
 {
     if (val > 0f && !m_Invincible)
     {
         m_Health -= val;
         if (m_Health <= 0)
         {
             Death();
         }
     }
 }
 
 public virtual void Heal(float val)
 {
     if (val > 0f)
     {
         m_Health += val;
         if (m_Health > m_MaxHealth)
         {
             m_Health = m_MaxHealth;
         }
     }
 }
 
 public float GetHealth()
 {
     return m_Health;
 }
 
 protected void Start() {
     bool error = false;
     if (m_MaxHealth <= 0)
     {
         Debug.LogError("Max health can't be less than or equal to 0");
         error = true;
     }
     if (m_Health > m_MaxHealth || m_Health <= 0)
     {
         Debug.LogError("Invalid health range expected 0-" + m_MaxHealth + " got " + m_Health);
         error = true;
     }
     if (error)
     {
         Debug.Break();
     }
 }    
 
 protected void Death()
 {
     if (m_DeathEffectPrefab != null)
     {
         Instantiate(m_DeathEffectPrefab, transform.position, transform.rotation);
     }
     if (animation != null && animation[m_DeathAnimation] != null)
     {
         animation.CrossFade(m_DeathAnimation, 0.3f, PlayMode.StopAll);
         if (m_RemainsPrefab != null)
         {
             StartCoroutine("WaitForDeathAnimation", animation[m_DeathAnimation].length);
         }
     }
     else
     {
         LogicalEvent(m_RemainsPrefab);
         //if (m_RemainsPrefab != null)
         //{
         //    Instantiate(m_RemainsPrefab, transform.position, transform.rotation);
         //}
         //Destroy(gameObject);
     }
 }
 
 void LogicalEvent(DecayingObject m_RemainsPrefab)
 {
     if (m_RemainsPrefab != null)
         {
             Instantiate(m_RemainsPrefab, transform.position, transform.rotation);
         }
                 Destroy(gameObject);
                 //Scoring.m_score += 10;
 }
 public void  LeftStatusMeter ( Texture charImage , Texture bBarImage , Texture hBarImage)
 {
 
 //Place Back Bars
 GUI.Label(new Rect(40, 10, 272, 90), bBarImage );
     
     //Place Front Bars
 GUI.BeginGroup( new Rect(100, 10, 218 * (Scoring.m_score * 10.0f), 90) );
 GUI.Label( new Rect(100, 0, 272, 90), hBarImage );
 GUI.EndGroup();
     
     GUI.EndGroup();
 }
 protected IEnumerator WaitForDeathAnimation(float time)
 {
     yield return new WaitForSeconds(time);
     Instantiate(m_RemainsPrefab, transform.position, transform.rotation);
     Destroy(gameObject);
 }
 void OnGUI()
 {
     GUI.color = Color.black;
     GUI.Label(new Rect(50, 25, 100, 30),"SCORE:");
     //Draw Background
         //GUI.skin = scoreSkin;
     
         GUI.color = Color.red;
     
     
 
 
     
     //GUI.Label(new Rect(100, 25, 100, 30),Scoring.m_score.ToString());
     
     //if(Scoring.m_score == 180)
     //{
     //        Application.LoadLevel(m_LevelToLoad = "WinScreen");    
     //        Scoring.m_score = 0;
     //}
     
     

} void Update(DecayingObject m_RemainsPrefab) {
LogicalEvent(m_RemainsPrefab); Scoring.m_score ++;

     //GUI.Box(new Rect(55,5,100,20),Scoring.m_score.ToString());
     //if(Scoring.m_score <= 180)
     //{
         
     //        Application.LoadLevel(m_LevelToLoad ="WinScreen");    
     //        Scoring.m_score == 0;
     //}
     
 }

}

Comment
Add comment · Show 1
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
avatar image Matt 5 · Jan 25, 2012 at 10:04 PM 0
Share

What section did u edit?

I commented a lot of stuff out and just left it in the code

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Berenger · Jan 27, 2012 at 03:37 AM

Apparently, you don't call your function LeftStatusMeter anywhere. Anyway, you'd have an error if you did, because of the second EndGroup();

If it still doesn't show, make sure you've got the right textures and that your variable score behave like you wants.

Comment
Add comment · Share
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

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

How to create a GUI like Zombieville? 1 Answer

Timer progress bar 0 Answers

Health bar by percentage? (not drawing a box) 4 Answers

Displaying final score using image textures 1 Answer

3D ^ Custom GUIText/Label or Making a Score System without using GUI? 0 Answers


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