- Home /
GUI Texture Fade in/out (Android)
Hi ! :) I run into a problem . I decided to make into my project the Standard Assets (Mobile)/Player Relative Setup . Want to make that so if i touch the joystick (left) then the joystick will fade up (because it has the alpha channel on 0) and when i release the joystick then fade down into 0 on the alpha channel . I only need to implement touch into this script but it don't work for me . So please help me out :) Here is the script :
#pragma strict
var myGUItexture : GUITexture;
function Start () {
yield Fade(0.0, 1.0, 2.0); // fade up
yield Fade(1.0, 0.0, 2.0); // fade down
}
function Fade (startLevel :float, endLevel :float, duration :float) {
var speed : float = 1.0/duration;
for (var t :float = 0.0; t < 1.0; t += Time.deltaTime*speed) {
myGUItexture.color.a = Mathf.Lerp(startLevel, endLevel, t);
yield;
}
}
Answer by ScroodgeM · Jul 28, 2012 at 07:46 PM
try this. i'm not strong in JS.
var rect = Rect (100, 100, 150, 150); // this is your screen's rect where touch will be handled
function Update () { if(Input.touchCount > 0) { var touch: Touch = Input.touches[0]; if(touch.phase == TouchPhase.Began && rect.Contains(touch.position)) { StartCoroutine(Fade(0.0, 1.0, 2.0)); } else if (touch.phase == TouchPhase.Ended) { StartCoroutine(Fade(1.0, 0.0, 2.0)); } } }
Thanks , Scroodge ! It works perfectly :) But , is possible to upgrade this script ? I want so that if the GUI Texture has been touched , not on the whole screen . Because i need it for the mobile controller to hide it , if you don't touching the controllers .
i'd edit answer. also, you can use ins$$anonymous$$d of GUI Texture just a GUI Button, is this way you needn't to handle touches and active rect at all.