I have a working health/energy bar scrip working with some textures and it’s fine, I can control the placement a little better with the scrip below, but If i change resolutions the width of the bar scales accordingly, which isn’t what I want, I want to know where the start and ending points of my bar will be or hopefully make it static so I can place some text-meshes next to it etc…
So I wondered is there such a script/feature which doesn’t use OnGUI()? if it wasn’t for this scaling problem (lower the resolution and the bar becomes smaller) I’d love what I have, but anyway thanks, hopefully I can find a solution as I’ve been battling with the placement of this object for far too long, cheers
using UnityEngine;
using System.Collections;
public class EnergyBarScript : MonoBehaviour
{
public float native_width = 1920;
public float native_height = 1080;
public Texture backgroundTexture;
public Texture foregroundTexture;
public int healthWidth = -400;
public int healthHeight = 41;
public int healthMarginLeft = 800;
public int healthMarginTop = 1030;
public int frameWidth = -378;
public int frameHeight = 0;
public int frameMarginLeft = 792;
public int frameMarginTop = 700;
void OnGUI ()
{
float rx = Screen.width / native_width;
float ry = Screen.height / native_height;
GUI.matrix = Matrix4x4.TRS (Vector3.zero, Quaternion.identity, new Vector3 (rx, ry, 1));
GUI.DrawTexture (new Rect (frameMarginLeft, frameMarginTop, frameMarginLeft + frameWidth, frameMarginTop + frameHeight), backgroundTexture, ScaleMode.ScaleToFit, true, 0);
GUI.DrawTexture (new Rect (healthMarginLeft, healthMarginTop, healthWidth + healthMarginLeft, healthHeight), foregroundTexture, ScaleMode.ScaleAndCrop, true, 0);
}
}