Creating Object Blink effect by Changing Color| 2D/3D Object | Color Lerp | Unity Game Engine


BlinkEffect.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
using UnityEngine;
 
public class BlinkEffect : MonoBehaviour
{
    public Color startColor = Color.green;
    public Color endColor = Color.black;
    [Range(0,10)]
    public float speed = 1;
 
    Renderer ren;
 
    void Awake()
    {
        ren = GetComponent<Renderer>();
    }
 
    void Update()
    {
        ren.material.color = Color.Lerp(startColor, endColor, Mathf.PingPong(Time.time * speed, 1));
    }
}