30 lines
926 B
C#
30 lines
926 B
C#
using System.Collections.Generic;
|
||
using UnityEngine;
|
||
|
||
[RequireComponent(typeof(Animator))]
|
||
public class IdleAnimationDistributor : MonoBehaviour
|
||
{
|
||
[Range(0,1)]
|
||
[SerializeField] float idleAnimationProb = 0.3f;
|
||
|
||
public List<string> idleTriggers = new List<string>();
|
||
private List<string> tempIdleTriggers = new List<string>();
|
||
|
||
|
||
public void _distributeIdleState()
|
||
{
|
||
//проверяем верояность. Не проходим - отсекаем
|
||
float rand = Random.Range(0.0f, 1.0f);
|
||
if (rand > idleAnimationProb) return;
|
||
|
||
//пустой список - копируем
|
||
if (tempIdleTriggers.Count == 0)
|
||
tempIdleTriggers = new List<string>(idleTriggers);
|
||
|
||
string trigger = tempIdleTriggers[Random.Range(0, tempIdleTriggers.Count)];
|
||
tempIdleTriggers.Remove(trigger);
|
||
|
||
GetComponent<Animator>().SetTrigger(trigger);
|
||
}
|
||
}
|