- Home /
Question by
TrewSx · Apr 29, 2013 at 10:01 PM ·
javascripttexturegui.window
How to make a Texture change in GUI.Window
Hi i am trying to change my Texture inside GUI.Window when the Player is hit or he does a hit to the enemy and have there no Texture if he does nothing from these two.
So far i've got the Textures working, but when i am in the game and do nothing the first Texture is always loaded inside my Window, i want to have that window clear and Texture to appear only when i do a hit or receive a hit.
#pragma strict
var mtSkin: GUISkin;
var hudPanelWidth : int;
var hudPanelHeight : int;
var attackicon : Texture;
var defenceIcon : Texture;
private var _hudWindowRect : Rect = new Rect(0,Screen.height - 90,250,100);
private static var _hudWindowID : int = 3;
private var console : Console;
private var player : GameObject;
function Start () {
player = GameObject.FindGameObjectWithTag("Player");
console = player.GetComponent(Console);
}
function OnGUI () {
GUI.skin = mySkin;
GUI.backgroundColor = Color.black;
GUI.color = Color.white;
_hudWindowRect = GUI.Window(_hudWindowID, _hudWindowRect, AttackPanelHUD, GUIContent (console.enemyAttackLabel, defenceIcon) || GUIContent (console.playerAttackLabel, attackicon ));
}
function AttackPanelHUD (_hudWindowID) {
// var temp : String = "";
// temp = console.enemyAttackLabel;
//
//
//
// var temp2 : String = "";
// temp2 = console.playerAttackLabel;
}
Comment
Best Answer
Answer by Fornoreason1000 · Apr 29, 2013 at 10:12 PM
OK just tell OnGUI or Console or whatever to only draw any of the textures you your doing one of those things, if not it will do nothing. (use IF's) do this before you determine which texture to display
Answer by TrewSx · May 01, 2013 at 06:45 PM
It's working now, take a look
#pragma strict
var AttackHUDSkin : GUISkin;
var hudPanelWidth : int;
var hudPanelHeight : int;
var attackicon : Texture;
var defenceIcon : Texture;
private static var _hudWindowID1 : int = 3;
private static var _hudWindowID2 : int = 4;
private var _displayAttackAndDefenceTextures : boolean = true;
private var _displayAttackTextures : boolean = false;
private var _displayDefenceTextures : boolean = false;
private var console : Console;
private var player : GameObject;
function Start () {
player = GameObject.FindGameObjectWithTag("Player");
console = player.GetComponent(Console);
}
function OnGUI () {
GUI.BeginGroup (Rect (0,Screen.height - 150,500,150));
//GUI.Box (new Rect (0,0,250,75), "Bottom-left");
//GUI.Box (new Rect (0,75,250,75), "Bottom-left2");
GUI.skin = AttackHUDSkin;
GUI.backgroundColor = Color.gray;
GUI.color = Color.white;
var _hudWindowRect1 : Rect = new Rect(0,Screen.height - 115,250,65);
var _hudWindowRect2 : Rect = new Rect(0,Screen.height - 50,250,75);
if (_displayAttackAndDefenceTextures) {
_hudWindowRect1 = GUI.Window(_hudWindowID1, _hudWindowRect1, AttackPanelHUD, GUIContent (console.enemyAttackLabel ));
_displayAttackTextures = true;
_hudWindowRect2 = GUI.Window(_hudWindowID2, _hudWindowRect2, AttackPanelHUD2, GUIContent (console.playerAttackLabel ));
_displayDefenceTextures = true;
}
GUI.EndGroup();
}
function AttackPanelHUD (_hudWindowID) {
if (_displayAttackTextures) {
GUI.Button (Rect (0, 0, 65, 65), GUIContent (defenceIcon));
}
}
function AttackPanelHUD2 (_hudWindowID) {
if (_displayDefenceTextures == true) {
GUI.Button (Rect (0, 0, 65, 65), GUIContent (attackicon));
}
}
Your answer
