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;
//}
}
}