示例#1
0
 /*普通攻击*/
 protected void attack()
 {
     if (SkillStatu != SkillStatus.Attack)
     {
         //开始攻击
         SkillStatu = SkillStatus.Attack;
         //Debug.Log("attack!"); //执行攻击
         MonsterAnimator.SetTrigger("SwordAttack");
     }
     else
     {
         //正在攻击
         AnimatorClipInfo[] animatorClipInfos = MonsterAnimator.GetCurrentAnimatorClipInfo(0);
         if (animatorClipInfos[0].clip.name == "Idel")
         {
             //已经攻击完毕
             //Debug.Log("攻击完毕!");
             SkillStatu = SkillStatus.Busy;
             StartCoroutine(recoverFromSkill(3));
         }
         else
         {
         }
     }
 }
示例#2
0
    /*移动到城门前,攻击城门*/
    protected void AttackDoor()
    {
        turnLeft();
        Vector3 DoorPosition;

        DoorPosition = DoorObject.GetComponent <Transform>().position;

        float xDistance = this.GetComponent <Transform>().position.x - DoorPosition.x;

        if (xDistance > DoorAttackDistance)
        {
            // 尚未到达大门
            MonsterAnimator.SetBool("isRun", true);
            Vector3 translator = new Vector3(speed, 0.0f, 0.0f);
            MonsterTransform.Translate(translator);
        }
        else
        {
            //已经到达大门处
            MonsterAnimator.SetBool("isRun", false);
            MonsterAnimator.SetTrigger("SwordAttack"); //播放攻击动画
        }
    }
示例#3
0
    /*追踪玩家,到达指定位置进行攻击*/
    protected void chaseAndAttackPlayer()
    {
        Vector3 PlayerPosition;

        PlayerPosition = PlayerObject.GetComponent <Transform>().position;

        float xDistance = GetComponent <Transform>().position.x - PlayerPosition.x;
        float yDistance = GetComponent <Transform>().position.z - PlayerPosition.z;

        bool    isRun      = false;
        Vector3 translator = new Vector3();

        if (xDistance > PlayerAttackDistanceX)
        {
            //怪物在玩家的右侧且尚未接近
            isRun = true;
            turnLeft();
            translator.x = speed;
            direction    = true;
        }
        else if (xDistance < -1.0f * PlayerAttackDistanceX)
        {
            //怪物在玩家的左侧且尚未接近
            isRun = true;
            turnRight();
            translator.x = speed;
            direction    = false;
        }

        if (yDistance > PlayerAttackDistanceZ)
        {
            //怪物在玩家的上方侧且尚未接近
            isRun = true;
            if (direction)
            {
                //怪物面向左侧,z轴正方向向下
                translator.z = speed;
            }
            else
            {
                //怪物面向右侧,z轴正方向向上
                translator.z = -1.0f * speed;
            }
        }
        else if (yDistance < -1.0f * PlayerAttackDistanceZ)
        {
            //怪物在玩家的下方且尚未接近
            isRun = true;
            if (direction)
            {
                //怪物面向左侧,z轴正方向向下
                translator.z = -1.0f * speed;
            }
            else
            {
                //怪物面向右侧,z轴正方向向上
                translator.z = speed;
            }
        }

        if (isRun)
        {
            //尚未到达攻击地点
        }
        else
        {
            //已经到达攻击地点
            MonsterAnimator.SetTrigger("SwordAttack"); //播放攻击动画
        }
        MonsterAnimator.SetBool("isRun", isRun);
        if (direction)
        {
            Quaternion quaternion = Quaternion.Euler(0, 180, 0);
            MonsterTransform.rotation = quaternion;
        }
        else
        {
            Quaternion quaternion = Quaternion.Euler(0, 0, 0);
            MonsterTransform.rotation = quaternion;
        }

        MonsterTransform.Translate(translator);
    }