mardi 4 août 2015

GUIDrawTexture, image does not resize when I resize the game window

The title probably makes no sense But I did not know how else to explain it... I can better explain here.

I'm making a 3D game and I have the hud set to the bottom left corner and it will resize and adjust when I resize the Window/Pick a different resolution, but the Health/thirst bar stays in one area and does not adjust with it and stay on top of the hud...

In example if The hud is in the Bottom left and when I resize and change the resolution the health thirst bar stay one the left side but they go way up in the middle of the screen Hope that makes sense and stuff like that here is my code thanks in advance :)!

var hudSize : Vector2 = new Vector2(244, 500);
var size : Vector2 = new Vector2(240, 40);
var thirstSize : Vector2 = new Vector2(244,60);

var healthPos : Vector2 = new Vector2(20, 20);
var healthBarDisplay : float = 1;
var healthBarFull : Texture2D;



var hungerPos : Vector2 = new Vector2(20, 60);
var hungerBarDisplay : float = 1;
var hungerBarFull : Texture2D;

var thirstPos : Vector2 = new Vector2(20, 100);
var thirstBarDisplay : float = 1;
var thirstBarFull : Texture2D;

var healthFallRate : int = 150;
var hungerFallRate : int = 150;
var thirstFallRate : int = 100;

var hudPos : Vector2 = new Vector2(0, 0);
var hudDisplay : Texture2D;

var canJump : boolean = false;
var jumpTimer : float = 0.7;


function Start()
{
onMotor = GetComponent(CharacterController);
controller = GetComponent(CharacterController);
}

//OnScreenDrawing Textures
function OnGUI()
{


GUI.DrawTexture(new Rect (0, Screen.height - 125,244,125), hudDisplay);                  


//HealthBar
GUI.BeginGroup(new Rect (healthPos.x, healthPos.y, size.x, size.y));    
GUI.BeginGroup(new Rect (0, 0, size.x * healthBarDisplay, size.y));
GUI.DrawTexture(Rect(0, 0, size.x, size.y), healthBarFull);

GUI.EndGroup();
GUI.EndGroup();

//ThirstBar
GUI.BeginGroup(new Rect (thirstPos.x, thirstPos.y, size.x, size.y));
GUI.BeginGroup(new Rect (0, 0, thirstSize.x * thirstBarDisplay, thirstSize.y));
GUI.DrawTexture(Rect(0, 0, thirstSize.x, thirstSize.y), thirstBarFull);


GUI.EndGroup();
GUI.EndGroup();


}


function Update()
{

if(hungerBarDisplay <= 100)
{
    healthBarDisplay -= Time.deltaTime / healthFallRate * 2;
    thirstBarDisplay -= Time.deltaTime / thirstFallRate * 5;
}



}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire