Need GUI help, need 2 scripts combined to work

So I’ve got a script which works with the actual health script for the character, which decreases and increases the box’s size from 0 - 100

using UnityEngine;
using System.Collections;

public class LifeBar : MonoBehaviour
{


    public GameObject player;
    public int maxHealth = 100;
    public float curHealth = 100;

    public float healthBarLength;

    void Start()
    {
        healthBarLength = Screen.width/2;



    }
    void Update()
    {
        AddjustCurrentHealth(0);
    }

    void OnGUI()
    {
        PlayerHealth playerHealth = player.GetComponent<PlayerHealth>();
        if (playerHealth != null)
        {
            float health =  playerHealth.playerHealth;
           // Debug.Log(health);
            curHealth = (int) health;
        }
       
         UnityEngine.GUI.Box(new Rect(10,10, healthBarLength ,20), curHealth + "/" + maxHealth );
    }

    public void AddjustCurrentHealth(int adj)
    {
        curHealth += adj;

        healthBarLength = (Screen.width/2)*(curHealth/(float) maxHealth);

    }

}

But I’ve been having immense trouble with hooking it up to the following script so that instead of a box, it’s a texture that doesn’t stretch.

  using UnityEngine;
using System.Collections;

public class GuiLoadTest : MonoBehaviour
{
    public float barDisplay; //current progress
    public Vector2 pos = new Vector2(20, 40);
    public Vector2 size = new Vector2(40, 20);
    public Texture2D emptyTex;
    public Texture2D fullTex;

    void OnGUI()
    {
        //draw the background:
        UnityEngine.GUI.BeginGroup(new Rect(pos.x, pos.y, size.x, size.y));
        UnityEngine.GUI.DrawTexture(new Rect(0, 0, size.x, size.y), emptyTex);

        //draw the filled-in part:
        UnityEngine.GUI.BeginGroup(new Rect(0, 0, size.x * barDisplay, size.y));
        UnityEngine.GUI.DrawTexture(new Rect(0, 0, size.x, size.y), fullTex);
        UnityEngine.GUI.EndGroup();
        UnityEngine.GUI.EndGroup();
    }



    void Update()
    {
        
        barDisplay = Time.time * 0.02f;
        //Stuff is meant to go here I think.
       
    }
}

Oops! You're trying to get it NOT to stretch. Ignore this answer and check out my other one....

One way to get an image to stretch (so it fills a GUI control's rectangle) is to use a GUIStyle.

You can apply the texture to the background property of the GUIStyle's normal state and then draw a GUI.Label (or Box, or Toggle) that uses your style. It would look like this:

GUI.Label(someRectangle, someText, theStyleYouCreated);

I believe that another approach would be to use the StretchToFill option, which would look something like this (although I thought this was the default):

GUI.DrawTextue(someRectangle, someImage, ScaleMode.StretchToFill);

I'm not quite sure what you mean by "in stead of a box, it's a texture that doesn't stretch."

But... You do have access to the width and height of the texture. So, if you don't want it to stretch, you could simply specify the rectangle you want it to fit like this:

var theWidth  =  fullTex.width;
var theHeight =  fullTex.height;

var theRect   =  Rect(0, 0, theWidth, theHeight);

GUI.DrawTexture(theRect, fullTex);

Also... and I think this is what you're looking for:

I'm pretty sure if you specify a Texture as the second parameter to GUI.Label, it will be drawn without getting scaled. That would look like this:

GUI.Label(someRectangle, fullTex);

The more I read your confusing question, the more I think this is what you're after.

You could use this if you want the Texture to stay the same size while the rectangle that displays it changes size.

Sorry for the confusion guys.

Pretty much what i’m after is for the 2nd script to work as it is now (Able to move forward and backward the way it is whilst also being able to be connected to a health script.