You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
CrowdControl/Assets/Feel/MMTools/Tools/MMHelpers/MMImage.cs

45 lines
976 B
C#

3 months ago
using UnityEngine;
using System.Collections;
namespace MoreMountains.Tools
{
/// <summary>
/// Image helpers
/// </summary>
public class MMImage : MonoBehaviour
{
/// <summary>
/// Coroutine used to make the character's sprite flicker (when hurt for example).
/// </summary>
public static IEnumerator Flicker(Renderer renderer, Color initialColor, Color flickerColor, float flickerSpeed, float flickerDuration)
{
if (renderer==null)
{
yield break;
}
if (!renderer.material.HasProperty("_Color"))
{
yield break;
}
if (initialColor == flickerColor)
{
yield break;
}
float flickerStop = Time.time + flickerDuration;
while (Time.time<flickerStop)
{
renderer.material.color = flickerColor;
yield return MMCoroutine.WaitFor(flickerSpeed);
renderer.material.color = initialColor;
yield return MMCoroutine.WaitFor(flickerSpeed);
}
renderer.material.color = initialColor;
}
}
}