當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。