j'ai récupéré un script sur le net pour faire changer la couleur d'un objet progressivement, mais je n'arrive pas à le faire marcher, il ne se passe rien. Voici le lien: https://www.youtube.com/watch?v=oNz4I0RfsEg
Le tuto est fait pour faire une transition de couleurs sur des sprites 2d, j'ai dû l'adapter pour mon cube.
Je précise que je ne sais pas me servir des coroutines mais le tuto semble plutôt clair.
Code : Tout sélectionner
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class blueRampReact : MonoBehaviour {
void Start ()
{
Color c = GetComponent<Renderer> ().material.color;
c.a = 0f;
GetComponent<Renderer> ().material.color = c;
}
void update()
{
if (Input.GetKey (KeyCode.Q))
{
StartFading ();
}
}
IEnumerator FadeIn()
{
for (float f = 0.05f; f <= 1; f += 0.05f)
{
Color c = GetComponent<Renderer> ().material.color;
c.a = f;
GetComponent<Renderer> ().material.color = c;
yield return new WaitForSeconds(0.05f);
}
}
void StartFading()
{
StartCoroutine ("FadeIn");
}
}