This is script is attached to a black plane. I have a plane and i added to it a material and the plane is in black. When running the game the alpha color of the plane material is changing slowly.
The script is working it's getting slowly from dark black to none black. But i want to make some changes:
It's not my script i took it from the youtube and did some changes the first one converted from js to c# second added the fade bool variable.
First of all i don't see any meaning setting the variable timer to 10 at the top. Any ideas what is the point ? Second is how can i check when the alpha color value is high enough to do some stuff:
Enabled true the fpc again. Once it's not black again the fpc is still enabled false.
If i want when the alpha color value reached it's max to make automatic fade back to black Now i'm using manual fade bool variable but i wonder how to do it automatic fade in/out.
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityStandardAssets.Characters.FirstPerson;
public class FadeScript : MonoBehaviour { public float timer = 10.0f; public FirstPersonController fpc; public bool fade = true;
// Use this for initialization void Start() { Color tempcolor = GetComponent<Renderer>().material.color; tempcolor.a = 1f; GetComponent<Renderer>().material.color = tempcolor; fpc.enabled = false; } // Update is called once per frame void Update() { timer = Time.deltaTime; if (timer >= 0) { Color tempcolor = GetComponent<Renderer>().material.color; if (fade == true) { tempcolor.a -= 0.1f * Time.deltaTime; } else { tempcolor.a += 0.1f * Time.deltaTime; } GetComponent<Renderer>().material.color = tempcolor; } }
}