BerkinAkkaya

Blink Effect

Nov 12th, 2018
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.52 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class Enemy : MonoBehaviour {
  5.  
  6.     SpriteRenderer spriteRenderer;
  7.  
  8.     void Start()
  9.     {
  10.         spriteRenderer = GetComponent<SpriteRenderer>();
  11.     }
  12.  
  13.     public void ReceiveHit()
  14.     {
  15.         StartCoroutine("Blink", 2);
  16.     }
  17.  
  18.     IEnumerator Blink(int count)
  19.     {
  20.         for(int i = 0; i < count; i++)
  21.         {
  22.             spriteRenderer.color = new Color(0.5f, 0,0);
  23.             yield return new WaitForSeconds(0.05f);
  24.             spriteRenderer.color = Color.red;
  25.             yield return new WaitForSeconds(0.05f);
  26.         }
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment