2026-07-14 11:14:13 +03:00

30 lines
926 B
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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);
}
}