In the method SelectAnimation i want that if i change the mode to None then set the linerenderer color to Red either before running the game or while the game is running.
The problem is that the method SelectAnimation get IEnumerator.
I could use the default state now it’s setting to null but i’m not sure how to do it.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[RequireComponent(typeof(LineRenderer))]
public class LineRendererColors : MonoBehaviour
{
public enum AnimationType { None, SingleColorMorph, MultiColorMorph, Shuffle, Shift };
LineRenderer myLineRenderer;
Coroutine _animationInProgress;
public float morphTime;
[SerializeField]
AnimationType _animationType;
#if UNITY_EDITOR
AnimationType _cachedAnimationType;
void OnValidate()
{
if (_animationType != _cachedAnimationType)
{
if (_animationInProgress == null)
_cachedAnimationType = _animationType;
else
StartAnimation(_animationType);
}
}
#endif
void StartAnimation(AnimationType animType)
{
_animationType = animType;
#if UNITY_EDITOR
_cachedAnimationType = animType;
#endif
if (_animationInProgress != null)
StopCoroutine(_animationInProgress);
_animationInProgress = StartCoroutine(SelectAnimation(animType));
}
IEnumerator SelectAnimation(AnimationType animType)
{
switch (animType)
{
case AnimationType.SingleColorMorph:
return RandomSingleColorMorphing(myLineRenderer, morphTime);
case AnimationType.MultiColorMorph:
return RandomMultiColorMorphing(myLineRenderer, morphTime);
case AnimationType.Shuffle:
return ShuffleGradient(myLineRenderer, .5f);
case AnimationType.Shift:
return AnimateLoop(myLineRenderer);
default:
return null;
}
}
void Start()
{
myLineRenderer = GetComponent<LineRenderer>();
StartAnimation(_animationType);
}