Advertisement
Guest User

Blink.cs

a guest
Jul 13th, 2019
607
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.92 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class Blink : MonoBehaviour
  6. {
  7.     SkinnedMeshRenderer rendererFace;
  8.     [SerializeField]
  9.     private AnimationCurve animationCurve;
  10.  
  11.     // Start is called before the first frame update
  12.     void Start()
  13.     {
  14.         rendererFace = GetComponent<SkinnedMeshRenderer>();
  15.     }
  16.  
  17.     // Update is called once per frame
  18.     void Update()
  19.     {
  20.         if (Input.GetKeyDown(KeyCode.B))
  21.         {        
  22.             StartCoroutine(Blink(0.3f));
  23.         }
  24.     }
  25.  
  26.  
  27.     IEnumerator Blink(float duration)
  28.     {
  29.         float time = 0f;
  30.         while (time <= duration)
  31.         {
  32.             time = time + Time.deltaTime;
  33.             float percent = Mathf.Clamp01(time / duration);
  34.             rendererFace.SetBlendShapeWeight(0, (animationCurve.Evaluate(percent) * 100));
  35.             yield return null;
  36.         }
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement