Merci Greg mais ça ne fonctionne pas.
Le fade in se fait immédiatement sans qu'on appuie sur la touche "F" et ça reste comme ça sans jamais de fade out.
La valeur temps est bien gérée mais l'alpha fait n'importe quoi...
Voici comment j'ai implémenté ton code...
Code : Tout sélectionner
using UnityEngine;
using System;
using System.Collections;
public class color2 : MonoBehaviour
{
public Color altColor = Color.black;
public Renderer rend;
public int temps;
void Example()
{
altColor.r = 0.33f;
altColor.g = 0.75f;
altColor.b = 1f;
altColor.a = 0f;
temps = 0;
}
void Start()
{
Example();
rend = GetComponent<Renderer>();
rend.material.color = altColor;
}
// void Update()
// {
// if (Input.GetKeyDown(KeyCode.F) && temps == 0)
// {
// temps = 500;
// rend.material.color = altColor;
//}
//if (altColor.a <= 1)
// altColor.a += 0.005f;
// rend.material.color = altColor;
// if (temps > 0)
//{
// temps -= 1;
//}
//else if (temps == 0 && altColor.a > 0)
// {
// altColor.a = 0f;
//altColor.a -= 0.005f;
//rend.material.color = altColor;
//}
//Debug.Log(altColor.a);
//}
//}
void Update()
{
if (temps > 0 && temps != 0)
temps--;
if (Input.GetKeyDown(KeyCode.F) && temps <= 0)
temps = 100;
if (altColor.a < 1)
altColor.a += 0.005f;
else if (altColor.a > 0 && temps == 0)
altColor.a -= 0.005f;
rend.material.color = altColor;
Debug.Log(rend.material.color.a);
}
}