using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[RequireComponent(typeof(Animator))]
public class PlayerAnimation : MonoBehaviour
{
[SerializeField] private SkinnedMeshRenderer face;
[SerializeField] private int animationsNum;
[SerializeField] private float animationTime;
[SerializeField] private Material[] emotions;
private Animator animator;
private int anim;
private void Awake()
{
animator = GetComponent<Animator>();
NewDance();
}
void NewDance()
{
face.materials[1] = emotions[0];
Debug.Log(face.materials[1].ToString());
anim = Random.Range(0, animationsNum);
if (anim == animator.GetInteger("Animation"))
{
anim++;
if (anim == animationsNum) anim = 0;
}
animator.SetTrigger("Start");
animator.SetInteger("Animation", anim);
StartCoroutine(NextDance());
}
IEnumerator NextDance()
{
yield return new WaitForSeconds(animationTime);
NewDance();
}
}