hello guys,
i am using following code to fade an object.its working fine but once object fade and if i bring other object again on faded object the faded object appers again and then fade again.i need once object fades its not appear again.Please help.
using UnityEngine;
using System.Collections;
public class DustFade : MonoBehaviour {
//Usethisforinitialization
void OnTriggerEnter2D (Collider2Dother){
if(other.tag =="Towel")
{
Start Coroutine(Fade());
}
}
IEnumerator Fade() {
for (floatf = 1f; f >= 0; f -= 0.1f) {
Colorc = renderer.material.color;
c.a = f;
renderer.material.color = c;
yield return new WaitForSeconds(0.30f);
}
}
}
You don’t seem to be putting much effort into this. It’s important that you learn how the code works and do some error-checking/exploration on your own.
It doesn’t do you much good as a developer if you come onto the forums and expect the users here to do all your work for you.
Make sure that ‘fade’ is UNCHECKED in the editor before you press play.