当前位置: 首页>>代码示例>>C#>>正文


C# Animator.Play方法代码示例

本文整理汇总了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"));

        }
开发者ID:TORISOUP,项目名称:Born_to_Beans_src,代码行数:50,代码来源:PlayerAnimation.cs

示例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);
        }
开发者ID:predominant,项目名称:Treasure_Chest,代码行数:9,代码来源:NoticeMessageUI.cs

示例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();
			
		}
开发者ID:SpacesAdventure,项目名称:Kio-2,代码行数:25,代码来源:AnimatorPlay.cs

示例4: Start

        // Use this for initialization
        void Start()
        {
            anim = GetComponent<Animator> ();
            anim.Play ("Take 001");

            //			print (anim.GetCurrentAnimatorClipInfo(0).);
        }
开发者ID:dlobser,项目名称:beach,代码行数:8,代码来源:switchAnimations.cs

示例5: Start

        // Use this for initialization
        void Start()
        {
            _motor = GetComponent<PlatformerMotor2D>();
            _animator = visualChild.GetComponent<Animator>();
            _animator.Play("Idle");

            _motor.onJump += SetCurrentFacingLeft;
        }
开发者ID:halfmonty,项目名称:OlafAndActeon,代码行数:9,代码来源:PlatformerAnimation2D.cs

示例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);
 }
开发者ID:wishes2018,项目名称:UnityGame,代码行数:8,代码来源:Attack.cs

示例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");
        }
开发者ID:KalleSjostrom,项目名称:Foundation,代码行数:10,代码来源:SceneTransition.cs

示例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;
        }
开发者ID:romsahel,项目名称:explorative-platformer,代码行数:12,代码来源:PlatformerAnimation2D.cs

示例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);
                }
            }
开发者ID:cupsster,项目名称:ExtremeBusiness,代码行数:15,代码来源:BehaviourBase.cs

示例10: OnStart

 public override void OnStart()
 {
     animator = GetComponent<Animator> ();
     animator.Play (animName);
 }
开发者ID:wishes2018,项目名称:UnityGame,代码行数:5,代码来源:PlayAnimat.cs

示例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;
			}
开发者ID:NotYours180,项目名称:UMA,代码行数:17,代码来源:UMAGeneratorBase.cs

示例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 };
 }
开发者ID:FabianBigler,项目名称:Projekt1_Unity,代码行数:18,代码来源:MonsterAI.cs

示例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;
        }
开发者ID:tenvick,项目名称:hugula,代码行数:38,代码来源:LuaHelper.cs

示例14: OnEnter

		public override void OnEnter ()
		{
			animator = ownerDefault.GetComponent<UnityEngine.Animator> ();
			animator.Play (hash, layer);
			Finish ();
		}
开发者ID:NusantaraBeta,项目名称:BrawlerRumble,代码行数:6,代码来源:Play.cs

示例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);
        }
开发者ID:harjup,项目名称:Xyz,代码行数:25,代码来源:Chaser.cs


注:本文中的UnityEngine.Animator.Play方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。