- Home /
Each consequtive mouse click removes a different Gui.Texture?
I am trying to figure out how to make a script so that each consecutive OnMouseDown or otherwise removes a different texture.
Specifically the energy-bar on the top left. The red panels are seperate png images, with the casing being it's own png image.
I need to make it so that when you shoot the gun, it removes a piece of the energy bar but I have no idea how to make OnMouseDown register different pieces for consecutive clicks or if that is even possible?
Any advice would be greatly appreciated!
Note: I am using Javascript and I have uploaded a picture of my EnergyBarScript.
Answer by Khada · Mar 11, 2013 at 02:29 AM
A pseudo example:
var activeBars : int = 10;
function Update()
{
if(Input.GetMouseButtonDown(0))
--activeBars;
}
function OnGUI()
{
GUI.depth = 1;
switch(activeBars)
{
case 10: GUI.DrawTexture(Rect(15,10,50,48), EnergybarTop); //top bar
case 9: /* draw next bar */ ;
case 8: /* draw next bar */ ;
case 7: /* draw next bar */ ;
case 6: /* draw next bar */ ;
case 5: /* draw next bar */ ;
case 4: /* draw next bar */ ;
case 3: /* draw next bar */ ;
case 2: /* draw next bar */ ;
case 1: GUI.DrawTexture(Rect(19,385,44,40), EnergybarBottom); //bottom bar
}
GUI.depth = 0;
}
Woops, I put --int; ins$$anonymous$$d of --activeBars;. I edited my answer. Try again.
I plugged the names of the textures into the / draw top bar /; section and so on and now it's telling me "Expressions in statements must only be executed for their side-effects."
var EnergybarShell: Texture; var EnergybarTop: Texture; var EnergybarBottom: Texture; var Energybar$$anonymous$$iddle2: Texture; var Energybar$$anonymous$$iddle3: Texture; var Energybar$$anonymous$$iddle4: Texture; var Energybar$$anonymous$$iddle5: Texture; var Energybar$$anonymous$$iddle6: Texture; var Energybar$$anonymous$$iddle7: Texture; var Energybar$$anonymous$$iddle8: Texture; var Energybar$$anonymous$$iddle9: Texture; var PDA: Texture;
var activeBars : int = 10;
function Update() { if(Input.Get$$anonymous$$ouseButtonDown(0)) --activeBars; }
static var guiDepth : int = 0;
function OnGUI(){ GUI.depth = guiDepth;
//EnergyBars GUI.depth = 1; GUI.DrawTexture(Rect(15,10,50,48), EnergybarTop);
GUI.depth = 1; GUI.DrawTexture(Rect(17,55,50,44), Energybar$$anonymous$$iddle2);
GUI.depth = 1; GUI.DrawTexture(Rect(14,100,50,40), Energybar$$anonymous$$iddle3);
GUI.depth = 1; GUI.DrawTexture(Rect(16,142,50,31), Energybar$$anonymous$$iddle4);
GUI.depth = 1; GUI.DrawTexture(Rect(14,177,51,40), Energybar$$anonymous$$iddle5);
GUI.depth = 1; GUI.DrawTexture(Rect(16,219,49,39), Energybar$$anonymous$$iddle6);
GUI.depth = 1; GUI.DrawTexture(Rect(19,258,44,45), Energybar$$anonymous$$iddle7);
GUI.depth = 1; GUI.DrawTexture(Rect(19,300,44,45), Energybar$$anonymous$$iddle8);
GUI.depth = 1; GUI.DrawTexture(Rect(19,340,44,45), Energybar$$anonymous$$iddle9);
GUI.depth = 1; GUI.DrawTexture(Rect(19,385,44,40), EnergybarBottom);
//EnergyBarShell GUI.depth = 0; GUI.DrawTexture(Rect(5,5,70,420), EnergybarShell);
//PDA GUI.depth = 1; GUI.DrawTexture(Rect(665,420,300,300), PDA);
switch(activeBars) { case 10: EnergybarTop ; case 9: Energybar$$anonymous$$iddle2 ; case 8: Energybar$$anonymous$$iddle3 ; case 7: Energybar$$anonymous$$iddle4 ; case 6: Energybar$$anonymous$$iddle5; case 5: Energybar$$anonymous$$iddle6 ; case 4: Energybar$$anonymous$$iddle7 ; case 3: Energybar$$anonymous$$iddle8 ; case 2: Energybar$$anonymous$$iddle9; case 1: EnergybarBottom; }
}
That is what I have so far, not sure if I am using your script improperly.
Your answer
Follow this Question
Related Questions
Import (Plz Help) 1 Answer
Instantiating material due to calling renderer.material during edit mode. 1 Answer
How to get at runtime the path of a Texture assigned in the editor ? 0 Answers
unable to fix texture on model in unity 1 Answer
Can you load images from outside the resources folder? 1 Answer