jimmy tremblay-Bernier 86fbe09b20 initial commit
2022-03-12 20:32:56 -05:00

54 lines
2.0 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CitizenCrowdMember : MonoBehaviour
{
public enum SelectableAnimation
{
Afraid,
Cheering
};
private Dictionary<SelectableAnimation, float> m_AnimationLenght = new Dictionary<SelectableAnimation, float>(){
{SelectableAnimation.Afraid, 920f/30},
{SelectableAnimation.Cheering, 237f/60}
};
public GameObject[] m_villagerPrefabs;
public GameObject m_placeholderToRemove;
public RuntimeAnimatorController m_animationController;
public SelectableAnimation m_currentAnimation = SelectableAnimation.Afraid;
public float m_blendingTime = 1;// Seconds
public float m_animationSpeedModificator = 1f;
private GameObject m_model;
private Animator m_modelAnimator;
private float m_blendingState = 0f;
private float m_animationTime = 0f;
// Start is called before the first frame update
void Start()
{
Destroy(m_placeholderToRemove, 0f);
m_model = Instantiate(m_villagerPrefabs[Random.Range(0, m_villagerPrefabs.Length)], this.transform);
m_model.transform.parent = this.transform;
m_modelAnimator = m_model.GetComponent<Animator>();
m_modelAnimator.runtimeAnimatorController = m_animationController;
m_animationTime = Random.Range(0f, 1f);
}
// Update is called once per frame
void Update()
{
if(m_currentAnimation == SelectableAnimation.Afraid){
m_blendingState = Mathf.Max(0, m_blendingState - (Time.deltaTime / m_blendingTime));
} else {
m_blendingState = Mathf.Min(1, m_blendingState + (Time.deltaTime / m_blendingTime));
}
m_modelAnimator.SetFloat("Blend", m_blendingState);
m_animationTime = (m_animationTime + (Time.deltaTime * m_animationSpeedModificator)/ m_AnimationLenght[m_currentAnimation]) % 1f;
m_modelAnimator.SetFloat("Time", m_animationTime);
}
}