Created
September 28, 2017 09:19
-
-
Save buijldert/cc787849031565d616d8678b0e7bf6a8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
using UnityEngine.UI; | |
public class ColorLerp : MonoBehaviour | |
{ | |
[SerializeField] | |
private Image _imageToLerp; | |
[SerializeField] | |
private bool _startsLerping; | |
private Color lerpedColor = Color.white; | |
[SerializeField] | |
public Color32 startColor = new Color32(66, 134, 244, 75); | |
[SerializeField] | |
public Color32 endColor = new Color32(10, 57, 132, 75); | |
private Coroutine _lerpColorCoroutine; | |
private void Start() | |
{ | |
if(_startsLerping) | |
{ | |
StartCoroutine(LerpColor()); | |
} | |
} | |
private IEnumerator LerpColor() | |
{ | |
lerpedColor = Color.Lerp(startColor, endColor, Mathf.PingPong(Time.time, 1)); | |
_imageToLerp.color = lerpedColor; | |
yield return null; | |
_lerpColorCoroutine = StartCoroutine(LerpColor()); | |
} | |
public void ControlLerp(bool isLerping) | |
{ | |
_imageToLerp.enabled = isLerping; | |
if (isLerping) | |
{ | |
_lerpColorCoroutine = StartCoroutine(LerpColor()); | |
} | |
else | |
{ | |
StopCoroutine(_lerpColorCoroutine); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment