- Home /
GUI DrawTexture is sliding across the screen?
Hi,
I am trying to implement a sort of sanity meter into my horror based platform game and I want. I have the code working and it does what it is supposed to, however, I am now having trouble making it so that it's a textured box I guess. I am new and just learning things and I have gotten pretty good at solving my own problems already, but I don't really understand this problem or much about GUI for that matter.
using UnityEngine;
using System.Collections;
public class Sanity : MonoBehaviour {
public float maxSanity = 100.0f;
public float curSanity = 100.0f;
public float sanityDrainSpeed = 100.0f; //# of milliseconds for 1 Health to drop.
public string sanity = "Sanity";
public Texture2D sanityImage;
void Start () {
}
void Update () {
curSanity = Mathf.Clamp(curSanity - (Time.deltaTime * (1000 / sanityDrainSpeed)),0.0f, maxSanity);
}
void OnGUI() {
GUI.DrawTexture (new Rect (10,24, Screen.width / 3 / (maxSanity / curSanity), 200),sanityImage);
Debug.Log (curSanity);
//GUI.DrawTexture(new Rect(350, 10, Screen.width / 2 /(maxSanity / curSanity), 25), sanity + curSanity + "/" + maxSanity);
}
}
So the problem is that if I use GUI.Label... it doesn't start to show decreased sanity until there isn't much left and then it just sort of gets smaller and smaller both vertically and horizontally which isn't ideal obviously.
Box is not ideal because it is just a plain old boring box.
Now, when I use DrawTexture, it does work except that as the sanity drops, the texture shrinks BUT it also slowly slides along the X axis.
I have no idea how to fix this. Please, please help.