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 BlinkEyeTracking : MonoBehaviour
- {
- SkinnedMeshRenderer rendererFace;
- [SerializeField]
- private AnimationCurve animationCurve;
- [SerializeField]
- int BlendShapeIndex_Eyes_Horizontal;
- [SerializeField]
- int BlendShapeIndex_Eyes_Vertical;
- float positionx;
- float positiony;
- Camera mainCam;
- // Start is called before the first frame update
- void Start()
- {
- rendererFace = GetComponent<SkinnedMeshRenderer>();
- mainCam = Camera.main;
- }
- // Update is called once per frame
- void Update()
- {
- if (Input.GetKeyDown(KeyCode.B))
- {
- StartCoroutine(Blink(0.3f));
- }
- positiony = Mathf.Clamp((mainCam.ScreenToViewportPoint(Input.mousePosition).y - 0.5f) * 100, -100, 100);
- positionx = Mathf.Clamp((mainCam.ScreenToViewportPoint(Input.mousePosition).x - 0.5f) * -100, -100, 100);
- rendererFace.SetBlendShapeWeight(BlendShapeIndex_Eyes_Vertical, positiony);
- rendererFace.SetBlendShapeWeight(BlendShapeIndex_Eyes_Horizontal, positionx);
- }
- 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