本文整理汇总了C#中UnityEngine.Animator.Play方法的典型用法代码示例。如果您正苦于以下问题:C# Animator.Play方法的具体用法?C# Animator.Play怎么用?C# Animator.Play使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnityEngine.Animator
的用法示例。
在下文中一共展示了Animator.Play方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Start
void Start()
{
animator = GetComponent<Animator>();
var cc = GetComponent<CharacterController>();
var core = GetComponent<PlayerCore>();
//ダメージを受けてアニメーション処理を中断している状態
var isAnimationDisabled = false;
//ダメージ受けたとき
core.OnPlayerDamagedObservable
.Do(_ =>
{
animator.Play("Damage");
IsRunning = false;
isAnimationDisabled = true;
})
//プレイヤが操作可能状態に戻るのを待つ
.SelectMany(_ => core.PlayerControllable.Where(x => x))
.FirstOrDefault()
.RepeatUntilDestroy(this.gameObject)
.TakeUntil(core.OnPlayerDeadAsObservable)
.Subscribe(_ => isAnimationDisabled = false);
//プレイヤの移動を監視してアニメーションを変える
cc.ObserveEveryValueChanged(x => x.velocity)
.TakeUntil(core.OnPlayerDeadAsObservable)
.Where(_ => !isAnimationDisabled)
.Subscribe(x =>
{
var speed = x.magnitude;
//走りモーション
IsRunning = speed > 0.1f;
//プレイヤの向き
if (!(speed > 0.1f)) return;
var forward = x.SuppressY();
if (!(forward.magnitude > 0)) return;
var lookRotation = Quaternion.LookRotation(forward);
transform.rotation = Quaternion.Lerp(
transform.rotation,
lookRotation,
Time.deltaTime * 20.0f
);
}).AddTo(this.gameObject);
core.OnPlayerDeadAsObservable
.Subscribe(_ => animator.Play("Dead"));
}
示例2: Awake
protected bool isHiding = false; // In the process of hiding
public virtual void Awake()
{
animator = GetComponent<Animator>();
if (showAnimation != null)
animator.Play(showAnimation.name);
}
示例3: OnEnter
public override void OnEnter()
{
// get the animator component
var go = Fsm.GetOwnerDefaultTarget(gameObject);
if (go==null)
{
Finish();
return;
}
_animator = go.GetComponent<Animator>();
if (_animator!=null)
{
int _layer = layer.IsNone?-1:layer.Value;
float _normalizedTime = normalizedTime.IsNone?Mathf.NegativeInfinity:normalizedTime.Value;
_animator.Play(stateName.Value,_layer,_normalizedTime);
}
Finish();
}
示例4: Start
// Use this for initialization
void Start()
{
anim = GetComponent<Animator> ();
anim.Play ("Take 001");
// print (anim.GetCurrentAnimatorClipInfo(0).);
}
示例5: Start
// Use this for initialization
void Start()
{
_motor = GetComponent<PlatformerMotor2D>();
_animator = visualChild.GetComponent<Animator>();
_animator.Play("Idle");
_motor.onJump += SetCurrentFacingLeft;
}
示例6: OnStart
public override void OnStart()
{
animator = GetComponent<Animator> ();
animator.Play ("attack");
tree = GetComponent<BehaviorTree> ();
SharedGameObject enemy = (SharedGameObject)tree.GetVariable ("enemy");
transform.LookAt (enemy.Value.transform.position);
}
示例7: Start
void Start()
{
_fadeTexture = new Texture2D(1, 1);
_fadeTexture.SetPixel(0, 0, new Color(0, 0, 0));
_fadeTexture.Apply();
_animator = gameObject.GetComponent<Animator>();
_animator.Play("FadeIn");
}
示例8: Start
// Use this for initialization
void Start()
{
audioSource = GetComponent<AudioSource>();
jump = Resources.Load("Audio/jump") as AudioClip;
_player = GetComponent<Player>();
_motor = GetComponent<PlatformerMotor2D>();
_animator = visualChild.GetComponent<Animator>();
_animator.Play("Idle");
_motor.onJump += SetCurrentFacingLeft;
}
示例9: Activate
// Activate a Mecanim animation
private void Activate(Animator animator)
{
if (animationState == empty) return;
if (resetNormalizedTime) {
if (crossfadeTime > 0f) animator.CrossFadeInFixedTime(animationState, crossfadeTime, layer, 0f);
else animator.Play(animationState, layer, 0f);
}
else {
if (crossfadeTime > 0f) {
animator.CrossFadeInFixedTime(animationState, crossfadeTime, layer);
} else animator.Play(animationState, layer);
}
}
示例10: OnStart
public override void OnStart()
{
animator = GetComponent<Animator> ();
animator.Play (animName);
}
示例11: RestoreAnimatorState
public void RestoreAnimatorState(Animator animator)
{
animator.applyRootMotion = applyRootMotion;
animator.updateMode = updateMode;
animator.cullingMode = cullingMode;
if (animator.layerCount == stateHashes.Length)
{
for (int i = 0; i < animator.layerCount; i++)
{
animator.Play(stateHashes[i], i, stateTimes[i]);
}
}
animator.Update(0.00001f);
animator.enabled = animating;
}
示例12: Start
// Use this for initialization
private void Start()
{
enemySight = GetComponent<EnemySight>();
enemySight.onlyTargetNPC = onlyTargetNPC;
nav = GetComponent<NavMeshAgent>();
//player = GameObject.FindGameObjectWithTag("Hero").transform;
animator = GetComponent<Animator>();
animator.Play("creature1walkforward");
// get the components on the object we need ( should not be null due to require component so no need to check )
nav = GetComponentInChildren<NavMeshAgent>();
//character = GetComponent<ThirdPersonCharacter>();
nav.updateRotation = true;
nav.updatePosition = true;
patrolWayPoints = new [] { patrolWayPoint1, patrolWayPoint2 };
nav.destination = patrolWayPoints[wayPointIndex].position;
//int[] n3 = { 2, 4, 6, 8 };
}
示例13: PlayAnimator
/// <summary>
/// 播放动画片段
/// </summary>
/// <param name="anim"></param>
/// <param name="name"></param>
/// <param name="dir"></param>
/// <returns></returns>
public static AnimatorStateInfo PlayAnimator(Animator anim, string name, AnimationDirection dir)
{
var state = anim.GetCurrentAnimatorStateInfo (0);
float speed = anim.GetFloat("speed");
float normalizedTime = 1;
if (dir == AnimationDirection.Toggle)
{
if (speed > 0)
dir = AnimationDirection.Reverse;
else
dir = AnimationDirection.Forward;
}
if (dir == AnimationDirection.Reverse)
{
anim.SetFloat("speed", -1 * Mathf.Abs(speed));
normalizedTime = 1;
}
else if (dir == AnimationDirection.Forward )
{
anim.SetFloat("speed", Mathf.Abs(speed));
normalizedTime = 0;
}
if (!string.IsNullOrEmpty(name))
anim.Play(name,0,normalizedTime);
else
anim.Play (state.fullPathHash,0,normalizedTime);
return state;
}
示例14: OnEnter
public override void OnEnter ()
{
animator = ownerDefault.GetComponent<UnityEngine.Animator> ();
animator.Play (hash, layer);
Finish ();
}
示例15: Start
public void Start()
{
MaxSpeed = Random.Range(8, 14);
_state = State.Run;
_playerMove = FindObjectOfType<Move>().gameObject;
_rigidbody = GetComponent<Rigidbody>();
_defaultLayer = gameObject.layer;
_grabLayer = LayerMask.NameToLayer("Chaser-Grab");
_stunnedLayer = LayerMask.NameToLayer("Chaser-Stun");
_grabStamina = GrabStaminaMax;
_cameraInput = Camera.main.GetComponent<CameraInput>();
_animator = GetComponentInChildren<Animator>();
_animator.Play("Walk");
_defaultMesh = transform.FindChild("Mesh").gameObject;
//_stunnedMesh = transform.FindChild("Mesh-Stunned").gameObject;
//_defaultMesh.SetActive(true);
//_stunnedMesh.SetActive(false);
}