using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class fadeobj : MonoBehaviour {
void Update() {
var animation = 1;
if (animation == 1)
{
StartCoroutine(FadeOutObject());
}
if (animation == 2)
{
StartCoroutine(FadeInObject());
}
}
public IEnumerator FadeOutObject() {
while (this.GetComponent<Renderer>().material.color.a > 0)
{
Color objectColor = this.GetComponent<Renderer>().material.color;
float fadeAmount = objectColor.a - ( 2 * Time.deltaTime);
objectColor = new Color(objectColor.r, objectColor.g, objectColor.b, fadeAmount);
this.GetComponent<Renderer>().material.color = objectColor;
var animation = 2;
yield return null;
}
}
public IEnumerator FadeInObject() {
while (this.GetComponent<Renderer>().material.color.a < 0 )
{
Color objectColor = this.GetComponent<Renderer>().material.color;
float fadeAmount = objectColor.a - ( -2 * Time.deltaTime);
objectColor = new Color(Random.value, Random.value, Random.value);
this.GetComponent<Renderer>().material.color = objectColor;
var animation = 1;
yield return null;
}
}
}