forked from cgvr/DeltaVR
add character sprites, mouth moving open closed
This commit is contained in:
60
Assets/_PROJECT/Scripts/NPCController.cs
Normal file
60
Assets/_PROJECT/Scripts/NPCController.cs
Normal file
@@ -0,0 +1,60 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
11
Assets/_PROJECT/Scripts/NPCController.cs.meta
Normal file
11
Assets/_PROJECT/Scripts/NPCController.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: baa11cfc03dc213438961722257e2e94
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user