***cropping GUI texture*** HELP

Firstly I’me a noob with scripting and C# so please dont be complicated if pos but C# is what ime using so Here is my problem…
Ive been folowing these Hack And slash rpg tutorials
and I’ve hit a problem in the making of the heath bar.
what i want is the health bar to be cropped not resized.

this is my health bar script.

/// <summary>
/// VitalBarHealth.cs
/// worldcrafter
/// 
/// 
/// This class is reponsible for displaying the vitals bar for the player character or spawn
/// </summary>

using UnityEngine;
using System.Collections;

public class VitalBarHealth : MonoBehaviour {
	
	public bool _isPlayerHealthBar;		//This boolean value tells us if this is the player healthbar or the mob healthbar
	
	private int _maxBarLength; 				//How long vital bar will be at 100% capacity
	private int _curBarLength;				//The current length of the vital bar
	private GUITexture _display;			//health bar texture
	
	void Awake() {
		_display = gameObject.GetComponent<GUITexture>();
	}
	
	// Use this for initialization
	void Start () {
//		_isPlayerHealthBar = true;
		
		
		
		_maxBarLength = (int)_display.pixelInset.width;
		
		
		OnEnable();
	
	}
	
	// Update is called once per frame
	void Update () {
	
	}
	
	//This method is called when the gameObject is enabled
	public void OnEnable() {
		if(_isPlayerHealthBar)
			Messenger<int, int>.AddListener("player health update", OnChangedHealthBarLength); 
		else {
			ToggleDisplay(false);
			Messenger<int, int>.AddListener("mob health update", OnChangedHealthBarLength);
			Messenger<bool>.AddListener("show mob vital bars", ToggleDisplay);
		}
	}
	
	//This method is called when the gameObject is disabled	
	public void OnDisable() {
		if(_isPlayerHealthBar)
			Messenger<int, int>.RemoveListener("player health update", OnChangedHealthBarLength); 
		else {
			Messenger<int, int>.RemoveListener("mob health update", OnChangedHealthBarLength);
			Messenger<bool>.RemoveListener("show mob vital bars", ToggleDisplay);
		}
		
	}
	
	//this will calculate the total size of the healthbar in relation to the % of health the target has left
	public void OnChangedHealthBarLength(int curHealth, int maxHealth) {
//		Debug.Log("We heard an event - curHealth:" + curHealth + " maxHealth:" + maxHealth); 
		_curBarLength = (int)((curHealth / (float)maxHealth) *_maxBarLength);		//this calculates the current length bar length based on player's health percentage
//		_display.pixelInset = new Rect(_display.pixelInset.x, _display.pixelInset.y, _curBarLength, _display.pixelInset.height);
		_display.pixelInset = CalculatePosition();
	}
	
	//setting the healthbar to the player or mob
	public void SetPlayerHealth(bool b) {
		_isPlayerHealthBar = b;	
	}
	
	private Rect CalculatePosition() {
		float yPos = _display.pixelInset.y / 2 - 14;
		
		if(!_isPlayerHealthBar){
			float xPos = (_maxBarLength - _curBarLength) - (_maxBarLength / 4 + 10);
			return new Rect(xPos, yPos, _curBarLength, _display.pixelInset.height);		
		}
		return new Rect(_display.pixelInset.x, yPos, _curBarLength, _display.pixelInset.height);	
	}
	
	private void ToggleDisplay(bool show) {
		_display.enabled = show;
	}
}

please help if you can i really want this… thanks

what do you mean crop instead of resized? are they not the same. Do you want it to be set at predefined increments instead of based of screen width and damage taken?

i mean i want a piece of the gui texture to be taken of not just squished up.

resizing is SQUISHING it together to the desired size
croping is REMOVING part of the image to get it to the desired size

bump

Groups crop images inside them

edit:nvm

i dont understand what that means, could some one put the code in my code for me and maybe a small explanation
thanks

they are saying, put your healthbar in

GUI.BeginGroup(Rect(location of healthbar,variable to decrease on damage, height of healthbar));
GUI.Label(Rect(0,0,length,height),texture);
GUI.EndGroup();

javascript is the best if you are doing simple GUIs just saying.

sry i suck and am a noob doing stuff thats beyond me- i get errors, could somebody put it into my code and then paste it as a reply please? it would make it much simpler and easier.
thanks for the help so far.

bump

bump

bump

bump