using System.Collections; using System.Collections.Generic; using UnityEngine; using DG.Tweening; public class NPCController : MonoBehaviour { private Vector3 mouthClosedScale; private Vector3 mouthOpenScale; private bool isTalking; public Transform mouthTransform; public float mouthScalingMultiplier = 2.5f; public float mouthMovementDuration = 0.25f; // Start is called before the first frame update void Awake() { mouthClosedScale = mouthTransform.localScale; mouthOpenScale = new Vector3(mouthClosedScale.x, mouthClosedScale.y * mouthScalingMultiplier, mouthClosedScale.z); isTalking = false; } // Update is called once per frame void Update() { } public void StartTalking() { isTalking = true; MoveMouth(); } public void Stoptalking() { isTalking = false; } private void MoveMouth() { if (!isTalking) { return; } if (mouthTransform.localScale == mouthClosedScale) { mouthTransform.DOScale(mouthOpenScale, mouthMovementDuration); } else { mouthTransform.DOScale(mouthClosedScale, mouthMovementDuration); } Invoke("MoveMouth", mouthMovementDuration + 0.01f); } }