Legacy Documentation: Version 5.3
LanguageEnglish
  • C#
  • JS

Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

Animator.GetBehaviours

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Sumbission failed

For some reason your suggested change could not be submitted. Please try again in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Switch to Manual
public function GetBehaviours(): T[];
public T[] GetBehaviours();

Description

Returns all StateMachineBehaviour that match type T or are derived from T. Returns null if none are found.

#pragma strict
// An example StateMachineBehaviour.
public class BreathBehaviour extends StateMachineBehaviour {
	public var fastBreath: boolean;
	// OnStateUpdate is called at each Update frame between OnStateEnter and OnStateExit callback
	public override function OnStateUpdate(animator: Animator, stateInfo: AnimatorStateInfo, layerIndex: int) {
		animator.SetBool("FastBreath", fastBreath);
	}
}
public class RunBehaviour extends StateMachineBehaviour {
	// OnStateUpdate is called at each Update frame between OnStateEnter and OnStateExit callback
	public override function OnStateUpdate(animator: Animator, stateInfo: AnimatorStateInfo, layerIndex: int) {
		var breathBehaviours: BreathBehaviour[] = animator.GetBehaviours.<BreathBehaviour>();
		for (var i: int = 0; i < breathBehaviours.Length(); i++)
			breathBehaviours[i].fastBreath = true;
	}
}
using UnityEngine;
using System.Collections;

// An example StateMachineBehaviour. public class BreathBehaviour : StateMachineBehaviour {

public bool fastBreath;

// OnStateUpdate is called at each Update frame between OnStateEnter and OnStateExit callback override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { animator.SetBool("FastBreath", fastBreath); } }

public class RunBehaviour : StateMachineBehaviour { // OnStateUpdate is called at each Update frame between OnStateEnter and OnStateExit callback override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { BreathBehaviour[] breathBehaviours = animator.GetBehaviours<BreathBehaviour>(); for(int i=0;i<breathBehaviours.Length();i++) breathBehaviours[i].fastBreath = true; } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961