- Home /
GUI Texture change width script. javascript
Im trying 2 hours to create script which change width of gui texture and i dont know how to do this. Somone help me with that... Please. texture is named 'healthbar' and tagged a 'bar'
and this is script:
#pragma strict
var MaxHealth = 100;
var Health : int;
var newInset : Rect = new Rect(50, 50, 100, 100);
function bar ()
{
if(Health - 10)
{
Gameobject.FindGameObjectWithTag("bar").GetComponent(GUITexture);
guiTexture.pixelInset = Rect (-524.4, 334.5, 250, 64);
}
}
function Start ()
{
Health = MaxHealth;
}
function ApplyDammage (TheDammage : int)
{
Health -= TheDammage;
if(Health <= 0)
{
Dead();
}
}
function Dead()
{
Debug.Log("Player Died");
}
function RespawnStats ()
{
Health = MaxHealth;
}
i have other idea i wanna add texture to GUI Box because if i change resolution my GUI texture is moving( in point of fact its the same place but resolution is changing), anyway. This is script of my Box GUI. Help me with adding texture .
var currentHealth : float = 100;
var maxHealth : int = 100;
var barLength = 500.0;
private var ch$$anonymous$$otor : Character$$anonymous$$otor;
function Start()
{
barLength = Screen.width / 8;
ch$$anonymous$$otor = GetComponent(Character$$anonymous$$otor);
}
function OnGUI()
{
GUI.Box(new Rect(140, 66, 350, 25), currentHealth.ToString("0") + "/" + maxHealth);
}
function AdjustCurrentHealth (adj)
{
currentHealth += adj;
if(currentHealth >= maxHealth)
{
currentHealth = maxHealth;
}
if(currentHealth <= 0)
{
currentHealth = 0;
}
}
bump.
I've no idea how your code is supposed to work. The code example at http://docs.unity3d.com/Documentation/ScriptReference/GUITexture-pixelInset.html does show how you can control the size in pixels of the GUI Texture.
yea nice now i can resize texture that not exist, please help me with add texture to gui box :x
Your answer
Follow this Question
Related Questions
How Do I Make A Health Bar 6 Answers
Health Bar 0 Answers
My healtbar is not change when i look another enemy 0 Answers
C# to Java UI Health Bar 1 Answer
Setting Scroll View Width GUILayout 1 Answer