- Home /
Question by
bayan_ · Apr 25, 2014 at 12:17 PM ·
c# to javascript
fade code for c#
i found this javaScript code to fade guiTexture the problem that i dont know javascript so can anyone help me changing this code to C#
function Start () {
yield Fade(0, .5, 5); // Start, end, length in seconds
renderer.enabled = false; }
function Fade (start : float, end : float, length : float) {
for (i = 0.0; i < 1.0; i += Time.deltaTime*(1/length)) {
guiTexture.color.a = Mathf.Lerp(start, end, i);
yield;
}
}
/*function End() {
yield Fade(.5, 0, 1); // Start, end, length in seconds
}*/
Comment
Best Answer
Answer by MikeNewall · Apr 25, 2014 at 02:13 PM
void Start(){
StartCoroutine(Fade(0, .5f,5));
renderer.enabled = false;
}
IEnumerator Fade(float start, float end, float length){
Color col = guiTexture.color;
for (float i = 0.0f; i < 1.0f; i += Time.deltaTime*(1/length)) {
col.a = Mathf.Lerp(start, end, i);
guiTexture.color = col;
yield return null;
}
}
*Not tested
Answer by BlackHoleStorm · Apr 25, 2014 at 02:38 PM
In theory, this should work. If not it should give you a better idea of what isn't working
void FadeFunc() //Run this function when you want it to fade
{
StartCoroutine(Fade(0f, 0.5f, 5)); //It might be a good idea to use public variables here so you can fine tune it in the editor
}
IEnumerator Fade (float start, float end, float length) {
for (i = 0.0; i < 1.0; i += Time.deltaTime*(1/length)) {
guiTexture.color.a = Mathf.Lerp(start, end, i);
yield return new WaitForSeconds(0.0f);
}
}
Your answer
