Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class Blink : MonoBehaviour
- {
- SkinnedMeshRenderer rendererFace;
- [SerializeField]
- private AnimationCurve animationCurve;
- // Start is called before the first frame update
- void Start()
- {
- rendererFace = GetComponent<SkinnedMeshRenderer>();
- }
- // Update is called once per frame
- void Update()
- {
- if (Input.GetKeyDown(KeyCode.B))
- {
- StartCoroutine(Blink(0.3f));
- }
- }
- IEnumerator Blink(float duration)
- {
- float time = 0f;
- while (time <= duration)
- {
- time = time + Time.deltaTime;
- float percent = Mathf.Clamp01(time / duration);
- rendererFace.SetBlendShapeWeight(0, (animationCurve.Evaluate(percent) * 100));
- yield return null;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement