えもふりでVtuberの真似事をする⑤ キー入力で表情を変える
前回まででマウスを目線で追い、喋りに合わせて口パクもしてくれるようになった。
今回は次のように表情を変えられるようにしてみたい。
今回は「Test3」のスクリプトを作成。前回と違うのは中身だけなので説明は省略。
以下スクリプト
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Test3 : MonoBehaviour
{
public EmotePlayer targetPlayer;
public float time;
// Start is called before the first frame update
void Start()
{
if (targetPlayer == null)
targetPlayer = this.GetComponent(typeof(EmotePlayer)) as EmotePlayer;
time=600;
}
// Update is called once per frame
void Update()
{
if (time>1) time--;
else targetPlayer.mainTimelineLabel="動作リセット";
//動作の操作部分
if (Input.GetKey(KeyCode.A)) {targetPlayer.mainTimelineLabel="sample_驚00";
time=240;
}
if (Input.GetKey(KeyCode.S)) {targetPlayer.mainTimelineLabel="sample_楽00";
time=240;
}
if (Input.GetKey(KeyCode.D)) {targetPlayer.mainTimelineLabel="微笑";
time=240;
}
if (Input.GetKey(KeyCode.W)) {targetPlayer.mainTimelineLabel="考える";
time=240;
}
}
}
ASDWのキー入力に合わせて表情が変わり、しばらく入力が無いと動作リセットをするようになる。
まあ、このままだと非アクティブなときは操作を受け付けないからちょっとアレ。一応、直せるっぽいので今度やります。
終わり。