在这种情况下,动画师包含3个项目。 但是,我不知道有多少个物品。可以是3或30。 我可以很好地获得“ medea_m_arrebola”索引,但是如何获取其余索引?
我也在2和现在1的这一行上尝试过:但是获取异常IndexOutOfRangeException:索引超出了数组的范围。
soldiers_indexs = new int[1];
如果不使用此行,我将在该行获取null:
soldiers_indexs[i] = i;
如何获取其余项目的索引?
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class OpenningScene : MonoBehaviour
{
[Header("Animators")]
public Animator[] animators;
[Space(5)]
[Header("Movement Settings")]
public Transform target;
public float movingSpeed = 1f;
public bool slowDown = false;
[Space(5)]
[Header("Rotation Settings")]
public float rotationSpeed;
public DepthOfField dephOfField;
public float waitingAnimation;
public float startConversation;
private Vector3 targetCenter;
private bool startWaitingAnim = true;
private bool endRot = false;
private int medea_m_arrebola_index;
private int[] soldiers_indexs;
// Use this for initialization
void Start()
{
targetCenter = target.GetComponent<Renderer>().bounds.center;
soldiers_indexs = new int[1];
for (int i = 0; i < animators.Length; i++)
{
animators[i].SetFloat("Walking Speed", movingSpeed);
if(animators[i].name == "medea_m_arrebola")
{
medea_m_arrebola_index = i;
}
else
{
soldiers_indexs[i] = i;
}
}
}