Hi guys I didn’t know if I should post it here or in the GUI forum but I am having a problem with my breath script. I want my texture to cut off area, or gradient the decreases. At the moment it just shrinks, I was wondering if there is any way to do it in the free version or is it a pro function only.
hmmm never done this my self, but one way I would believe works in the free version is to draw semi transparent GUI images on the whole screen? otherwise I do think there is some fade in/fade out scripts available for the free version too, look around mate
I think if you choose a shader with alpha u can probably fade it out
i dont think a shader work on a GUI does it?
I believe it does, I’ve made a mini map with shaders, however i do not know if it works in the free version.
Here is the code of the script that i have.
//Define variables
var underwaterLevel: float= 232.25;
var underWaterPlane: Transform;
static var curBreath : float = 100.0;
static var maxBreath : float = 100.0;
static var breathRegen : float = 0.175;
var breathBarTexture : Texture2D;
var breathBarLength : float;
var percentOfBreath : float;
//var myRect : Rect = Rect(0, 0, 100, 100);
function OnGUI () {
if (curBreath > 0){
// myRect.yMin += breathBarLength;
// GUI.DrawTextureWithTexCoords(Rect(((Screen.width/8)*7) - 100, 20, 100,100), breathBarTexture, myRect);
GUI.DrawTexture(Rect.MinMaxRect(((Screen.width/8)*7) - 100.0,(20.0 / breathBarLength),(((Screen.width/8)*7)*1.0), 100.0), breathBarTexture);
}
}
function Update () {
if (underWaterPlane.transform.position.y < underwaterLevel) {
percentOfBreath = curBreath/maxBreath;
breathBarLength = percentOfBreath*100;
if(curBreath < 0) {
curBreath = 0;
}
if(curBreath == 0){
Player_Stats.curHp = Player_Stats.curHp - (breathRegen*4);
}
if(curBreath > maxBreath) {
curBreath = maxBreath;
}
if(curBreath > 0) {
curBreath = curBreath - breathRegen;
}
}
else {
curBreath = maxBreath;
breathBarLength = 0;
}
}
Me and my friend are trying to work this out is there anyway we could have a mask that slides over it to make it look like it is decreasing. Or is our code the wrong way.
sure, but youre still gonna need to use a masking shader.
Cropping a texture in gui is easy, use Groups
for results like this
To fade it isntead, you will need to use a shader
would this work doing it vertical as well top to bottom
Cropping a square texture is easy ^
Cropping a round texture you still need to use a masked shader.
Look at texture mask here: http://wiki.unity3d.com/index.php/Shaders
Oh okay I am guessing that I cant use the GUI to call the shader on the texture of the object i would have to create a object instead?
is there anyway to reverse it so it fills up from the top to the bottom i am getting really confused on how to do that bit
Cropping a round texture in GUI is easy, use Groups
http://docs.unity3d.com/Documentatio...eginGroup.html
for results like this
For a fade instead, you will need to use a shader
hey is there anyway you give me the script of how you did that? So i can figure how to work it with my own script
GUI.DrawTexture(new Rect(5, 5, img2.width, img2.height), img2); //draw the background image
GUI.BeginGroup(new Rect(5, 5 + img1.width-someValue, img1.width, someValue)); //this group crops the top image
GUI.DrawTexture(new Rect(0, someValue-img2.height, img1.width, img1.height), img1);//draw the top image
GUI.EndGroup();
Thanks for that it really helped with me understanding how it works and it work well with my other scripts thanks
interesting.
pity youre using the built-in GUI
But doesnt NGUI cost?