示例#1
0
    public void SimpleMove(Vector3 targetPosition)
    {
        //朝向target
        dir.LookRotationTarget(targetPosition);

        //移动
        player.SimpleMove(transform.forward * speed);
    }
示例#2
0
    private void OnAttack()
    {
        if (targetNormalAttack == null)
        {
            playerState = PlayerState.ControlWalk;

            //这样可以避免攻击结束后又跑到之前指定的位置
            playerDir.targetPosition = transform.position;
            return;
        }

        playerDir.LookRotationTarget(targetNormalAttack.position);
        float distance = Vector3.Distance(targetNormalAttack.position, transform.position);

        //进行攻击
        if (distance <= minDistance)
        {
            //必须改变攻击状态,避免PlayerAnimation中同时执行跑的动画
            attackAnimState = AttackAnimState.Attack;

            animTimer += Time.deltaTime;
            anim.CrossFade(animNow);

            //动画播放完毕
            if (animTimer >= timerNormalAttack)
            {
                animNow = animIdle;
                //攻击效果是否显示过
                if (isShownEffect == false)
                {
                    isAttacked    = true;
                    isShownEffect = true;
                    //攻击特效
                    Instantiate(AttackEffect, targetNormalAttack.position, Quaternion.identity);
                    targetNormalAttack.GetComponent <Wolf>().TakeDamage(GetAttack());

                    AudioSource.PlayClipAtPoint(normalAttackSound, targetNormalAttack.position);
                }
            }

            //计时大于攻击速率,重新启动攻击
            if ((animTimer > (1f / attackRate)) && isAttacked)
            {
                animTimer = 0;
                animNow   = animNormalAttack;

                isShownEffect = false;
                isAttacked    = false;
            }
        }
        //走向敌人
        else
        {
            //设置状态即可,动画的播放在PlayerAnimation中控制了
            attackAnimState = AttackAnimState.Moving;
            playerMove.SimpleMove(targetNormalAttack.position);
        }
    }