Animator.GetLayerIndex
Declaration
public int GetLayerIndex(string layerName);Параметры
| Параметр | Описание |
|---|---|
| layerName | Имя слоя анимации для поиска. |
Возвращаемое значение
инт Индекс указанного слоя. Возвращает -1, если имя слоя не найдено.
Описание
Возвращает индекс слоя анимации с указанным именем.
Вы можете использовать Animator.GetLayerName для получения имени слоя анимации с помощью его индекса.
using UnityEngine; // This example demonstrates how to use the Animator.GetLayerIndex method to get the index of a layer by name and then // use it to set the weight of the layer. [RequireComponent(typeof(Animator))] public class GetLayerIndexExample : MonoBehaviour { public string layerName = "Injured"; public float weightDelta = 0.1f; private Animator m_Animator; private int m_LayerIndex; void Start() { m_Animator = GetComponent<Animator>(); // Get the index of the layer by name m_LayerIndex = m_Animator.GetLayerIndex(layerName); if (m_LayerIndex == -1) { Debug.LogWarning("Layer not found: " + layerName); } } void Update() { if (m_LayerIndex == -1) { return; } // Increase the weight of the layer when the Up arrow key is pressed if (Input.GetKeyDown(KeyCode.UpArrow)) { var currentWeight = m_Animator.GetLayerWeight(m_LayerIndex); m_Animator.SetLayerWeight(m_LayerIndex, currentWeight + weightDelta); } } }
Дополнительные ресурсы: AnimationLayers руководство.