我想知道如何将这些anims
存储在一个数组中,因为start函数会被触发一次。 我希望能够多次召唤这些Animators
。
public Animator anim0; public Animator anim25; public Animator anim50; public Animator anim75; public Animator anim100; void Start () { anim0 = GameObject.FindGameObjectWithTag("Campfire0").GetComponent<Animator>(); anim25 = GameObject.FindGameObjectWithTag("Campfire25").GetComponent<Animator>(); anim50 = GameObject.FindGameObjectWithTag("Campfire50").GetComponent<Animator>(); anim75 = GameObject.FindGameObjectWithTag("Campfire75").GetComponent<Animator>(); anim100 = GameObject.FindGameObjectWithTag("Campfire100").GetComponent<Animator>(); }
关于什么:
Animator[] anims = new Animator[number_of_animators]; anims[0] = anim0; ...
如果你的意思是在编辑器中有一个可编辑的数组,你可以声明它是公共的,你将在编辑器中指定它的大小,你将能够拖放元素到它
像这样:
public Animator[] anims;
这是被宣布为可变的。 不需要在Start()里初始化
然后检查正在播放哪个animation
AnimationInfo[] animPlayed;
什么时候需要打电话
animPlayed = you_animator.GetCurrentAnimationClipState (0);
它返回正在播放的第一个animation片段(因为你可能有更多的并发animation)