Hi I want to make simple item highlighting but not just popup new color bot slowly change to new color when mouse is over item and when it goes away it back to original color.
I found something that somewhat works when you use keyboard shortcuts and give function time to finish but when i tap one key after another instead of slowly change to original color it just change to new color and popup to orginal just like in mouseover/exit works, it seems that IEnumerator work for changing to new color and orginal at the same time and when new color is finish it just pop up orginal that finish tiny sec after
What I want is to make that smart script that slowly increase color to new one but when interrupt it go back to original from that point and I have absolutely no idea how to do it
Any help would be great
and here is my code
using UnityEngine;
using System.Collections;
public class leanScaleandColor : MonoBehaviour {
public Color[] c;
Color startColor ;
void Start () {
startColor = transform.renderer.material.color;
}
void Update () {
if (Input.GetKeyUp (KeyCode.T)) {
StartCoroutine (FadeTo (c [0], 1.0f));
}
if (Input.GetKeyUp (KeyCode.F)) {
StartCoroutine (FadeTo (startColor, 1.0f));
}
}
void OnMouseOver(){
StartCoroutine(FadeTo(c[0] , 1.0f));
}
void OnMouseExit(){
StartCoroutine(FadeTo(startColor, 1.0f));
}
IEnumerator FadeTo(Color NewColor, float aTime)
{
Color curentColor = transform.renderer.material.color;
for (float t = 0.0f; t < 1.0f; t += Time.deltaTime / aTime)
{
Color newColor2 = Color.Lerp (curentColor, NewColor, t);
transform.renderer.material.color = newColor2;
yield return null;
}
}
}