using System.Collections; using System.Collections.Generic; using UnityEngine; public class NPCController : MonoBehaviour { private Transform mouthTransform; private Vector3 mouthClosedScale; private Vector3 mouthOpenScale; private bool isTalking; public float mouthScalingMultiplier = 2.5f; // Start is called before the first frame update void Start() { mouthTransform = transform.GetChild(0).transform; 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.localScale = mouthOpenScale; } else { mouthTransform.localScale = mouthClosedScale; } Invoke("MoveMouth", 0.5f); } }