我拿伤害但我看不到动画

时间:2018-04-30 23:42:54

标签: unity3d

为了简化攻击动画(动画师有int参数,当它设置为4时控制攻击动画),即使int更改为4也不起作用。

我在另一个对象中使用了相同的代码,它完美无缺。

下面的屏幕截图显示了动画师控制和传输

using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    namespace UnityStandardAssets.Characters.FirstPerson
    {
        [RequireComponent(typeof (CharacterController))]
    public class BOSSATTACKS : MonoBehaviour {
            public GameObject prefabProjectil;
            private GameObject projectil;
            public Vector3 offset;
            public ParticleSystem tp;
            public ParticleSystem fire;
            public float timeBetweenFB = 20f;
            public float timeBetweenAttacks = 10f;
            public float timeBetweenTp = 30f;
            public int attackDamage = 10;
            public Animator anim;
            public GameObject boss;
            GameObject player;
            PlayerHealth playerHealth;
            bool playerInRange;
            float timer;

            void Awake ()
            {   
                player = GameObject.FindGameObjectWithTag ("Player");
                playerHealth = player.GetComponent <PlayerHealth> ();
            }


            void OnTriggerEnter (Collider other)
            {
                if(other.gameObject == player)
                {    
                    playerInRange = true;
                }
            }


            void OnTriggerExit (Collider other)
            {
                if(other.gameObject == player)
                {
                    playerInRange = false;
                }
            }


            void Update ()
            {
                timer += Time.deltaTime;

                if (timer >= timeBetweenAttacks && playerInRange)
                {
                    StartCoroutine (Attack ());                 
                }

                if (timer >= timeBetweenTp && playerInRange == false)
                {
                    StartCoroutine (tp1 ());        
                }      

            }

            IEnumerator tp1()
            {   timer = 0f;
                anim.SetInteger ("atk", 2);
                tp.Play ();
                yield return new WaitForSeconds(2);
                boss.transform.position = player.transform.position - offset;
                anim.SetInteger ("atk", 3);                
            }       

            IEnumerator  Attack ()
            {   
                timer = 0f;

                if (playerHealth.currentHealth > 0) { 
                    anim.SetInteger ("atk", 4);
                    yield return new WaitForSeconds (2);
                    playerHealth.TakeDamage (attackDamage);
                    anim.SetInteger ("atk", 3);

                }
            }
        }
    }

screenshot

0 个答案:

没有答案