Need help converting unityscript to c#

Can someone help me convert this script to C#?
It’s a health bar script

var healthTexture : Texture2D;
var healthBorder : Texture2D;
var curhealth : int = 100;
var maxhealth : int = 100;


function OnGUI () {

GUI.DrawTexture(Rect(43,Screen.height - 65,314,40), healthBorder);

var adjust : int = health * 3;
 GUI.BeginGroup(Rect(40,Screen.height - 67,adjust,30));
GUI.DrawTexture(Rect(0,0,323,46), healthTexture);
GUI.EndGroup();
}

And one more thing, I’m trying to insert something like that so that the “healthTexture” will move slide across (so it would look like it’s being depleted as any normal rpg game due to the percentage) I used the code I posted above, it worked but when the health is at like 50% the “healthTexture” is below halfway point on the “healthBorder”

adjust = (Screen.width / 4) * (curhealth / (float)maxhealth);

Thanks in advance!

How about something like this?

using UnityEngine;

public class SimpleHealthBar : MonoBehaviour {

	#region Editable properties
	public Texture2D healthTexture = null;
	public Texture2D healthBorder = null;
	// Pick a convenient parameterisation for background coordinates
	public Vector2 borderLocation = new Vector2(40f, 65f);
	public Vector2 borderSize = new Vector2(314f, 40f);
	// How far horizontally and vertically to offset the resizeable bar
	public Vector2 barInset = new Vector2(3f, 2f);
	// The largest permitted health Value
	public int maxHealth = 100;
	#endregion

	Rect _borderBox;
	Rect _barBox;
	int _currentHealth;

	// Read and change recorded health
	public int Health {
		get { return _currentHealth; }
		set { _currentHealth = (int)Mathf.Clamp(value, 0f, maxHealth); }
	}

	// Use this for initialization
	void Start () {
		// Fixed rectangle used to display the background texture
		_borderBox = new Rect(borderLocation.x, Screen.height - borderLocation.y,
			borderSize.x, borderSize.y);
		// Basis for drawing the health bar
		_barBox = new Rect(_borderBox.x + barInset.x, _borderBox.y + barInset.y,
			borderSize.x - 2f * barInset.x, borderSize.y - 2f * barInset.y);
		_currentHealth = maxHealth;
	}

	void OnGUI() {
		GUI.DrawTexture(_borderBox, healthBorder);
		// Draw less of the bar as health declines, trimming texture coordinates to match
		float f = Mathf.Clamp01(_currentHealth / (float)maxHealth);
		Rect texCoords = new Rect(0f,0f,f,1f);
		Rect trimmedPos = new Rect(_barBox.x, _barBox.y, f * _barBox.width, _barBox.height);
		GUI.DrawTextureWithTexCoords(trimmedPos, healthTexture, texCoords);
	}
}

For the script :

using UnityEngine;
using System.Collections;

public class MyLifeBarClassName : MonoBehaviour {

public Texture2D healthTexture;
public Texture2D healthBorder;
public int curhealth = 100;
public int maxhealth = 100;


        void OnGUI()
    {
        GUI.DrawTexture(new Rect(43,Screen.height - 65,314,40), healthBorder);
        int adjust = curhealth*3;
        GUI.BeginGroup(new Rect(40,Screen.height - 67,adjust,30));
        GUI.DrawTexture(new Rect(0,0,323,46), healthTexture);
        GUI.EndGroup();
  }

}

Ok here are the pics

Here with you code I placed the health to 100
alt text

Open images in new tab if too small
Other pic, when increased the bar goes down(Couldn’t upload since two uploads were the limit.

Got it like 90% working by combining your code and Rati’s code.
It just won’t display the texture due to the health percentage.

using UnityEngine;
using System.Collections;

public class NewBehaviourScript : MonoBehaviour {

public Texture2D healthTexture;
public Texture2D healthBorder;
public int curHealth = 100;
public int maxHealth = 100;
public float healthBarLength;
	private float percent;
	
	// Use this for initialization
	void Start () {
		healthBarLength = Screen.width / 4;
	}
// Update is called once per frame
	void Update () {
		AdjustCurrentHealth(0);
	}
        void OnGUI()
    {
        GUI.DrawTexture(new Rect(43,Screen.height - 65,314,40), healthBorder);
        GUI.BeginGroup(new Rect(40,Screen.height - 67,healthBarLength,60));
        GUI.DrawTexture(new Rect(31,10,242,15), healthTexture);
        GUI.EndGroup();
		 
  }
	public void AdjustCurrentHealth(int adj){
		curHealth += adj;
		
		if(curHealth < 1)
			curHealth = 0;
		
		if(curHealth > maxHealth)
			curHealth = maxHealth;
		
		if(maxHealth < 1)
			maxHealth = 1;
		percent = (curHealth / (float)maxHealth);
		healthBarLength = (Screen.width  *percent);
		
	}
	
}

Textures

using UnityEngine;
using System.Collections;

public class HEALTHBAR : MonoBehaviour {
Texture2D healthTexture;
Texture2D healthBorder;
int curhealth = 100;
int maxhealth = 100;
 
 
void  OnGUI (){
 
GUI.DrawTexture( new Rect(43,Screen.height - 65,314,40), healthBorder);
 
int adjust = health * 3;
 GUI.BeginGroup( new Rect(40,Screen.height - 67,adjust,30));
GUI.DrawTexture( new Rect(0,0,323,46), healthTexture);
GUI.EndGroup();
}

}

also, in the future you might find this site helpful: Convert Unityscript to C#
The output usually requires a touchup or two, but is generally pretty accurate.