GUI.DrawTexture Error & Static Variables!!

Hi, if anybody can help me here, i want to create a GUI on screen from a script that is assigned into a light prefab. Please don’t tell me to not put it there, the only other way i can combat that is if somebody told me how to use static variables where i declare the variable in one script (javascript) at the beginning of the script. The script is for a flashlight battery and it looks like this so far:

var torchBattery0Percent : Texture;
var torchBattery10Percent : Texture;
var torchBattery20Percent : Texture;
var torchBattery30Percent : Texture;
var torchBattery40Percent : Texture;
var torchBattery50Percent : Texture;
var torchBattery60Percent : Texture;
var torchBattery70Percent : Texture;
var torchBattery80Percent : Texture;
var torchBattery90Percent : Texture;
var torchBattery100Percent : Texture;

var weaponSelectHelp : Texture;

private var weaponNumber : float = 0;
public static var torchBattery : float = 1000;
// Weapon Numbers:
// 0 = Unarmed
// 1 = Torch

function Start (){

	GUI.DrawTexture(0.025f, 0.05f)(Rect(0,0,128,58), torchBattery100Percent);


function Update () {

	if(torchBattery > 1000){
		torchBattery = 1000;


	// If you are unarmed and you press tab, equip the torch
	if(weaponNumber == 0 && (Input.GetKeyDown ("tab"))){
		light.intensity = 1;
		weaponNumber = 1;
	else if(weaponNumber == 1 && (Input.GetKeyDown ("tab"))){
		light.intensity = 0;
		weaponNumber = 0;


	if(weaponNumber == 1){
		torchBattery = torchBattery - 1;
	else if(weaponNumber == 0){
		torchBattery = torchBattery + 1;
	if(torchBattery <= 0){
		light.intensity = 0;
		weaponNumber = 0;


	if(torchBattery <= 100){

Debug.Log(String.Format("Torch Value = {0}", torchBattery)); //########################################### COMMENT THIS OUT WHEN DONE

It is actually working fine in terms of the battery i want. BUT the thing that isn’t working about it is the textures i have for the battery percent. If you look in the start function, the problem that is constantly been brought up is this:

BCE0023: No appropriate version of ‘UnityEngine.GUI.DrawTexture’ for the argument list ‘(float, float)’ was found.

If anybody could help me with this i would be extremely thankful!!

Also if there is no way to combat this or it is a poor way to combat it, then what i would rather do is keep the variable ‘torchBattery’ as a public static variable (at the top with the rest of the declared variables) and access it from another script. THIS WOULD BE THE BEST WAY FOR ME but i just don’t know how i would be able to do it.

I’d like to know how to do it, and i tried to make another script to access the public static variable which looks like this:

var torchPercent : float = ChangeWeapon.torchBattery;

function Update () {

Debug.Log(String.Format("WOOOOOOOOOOAH = {0}", torchPercent));


The only reason i did ChangeWeapon.torchBattery is because the other script is called ChangeWeapon.js and the public static variable that i want to access is called torchBattery.

If you could help me this way it would be better, but the other way would be fine too - figuring out the error on GUI.DrawTexture…

But i need it to be permanently placed at a certain distance from the corner of the screen, regardless of the screen size. How would i do that? I also need it so that if the screen size is lower, the gui will get scaled down. The only other way i accomplished this was by using planes and materials. I don’t know any other way, because the pixel inset on a gui texture makes the gui start to go off screen when scaled down?!


I think you should document yourself a bit more on GUI in unity first. A LOT of good documentations exists.

Also: you can scale a texture to fit your needs, so you don’t need a different texture for every 10%.
Also, to scale the size depending on the screen resolution:

Try this (untested, but should be ok):

function OnGUI() {
	GUI.DrawTexture(Rect(10,10,128 /(1000/ torchBattery),58), torchBattery100Percent, ScaleMode.ScaleToFit);

This would create a texture on top left of the screen (at 10 pixel from left and 10 pixel from top, regardless of the screen size), of a size 128 pixel proportionally scaled to you torchBattery variable (if I’m correct torchBattery at 1000 = 100% in your code)

Using this, you only use “torchBattery100Percent” and can delete all your other textures