示例#1
0
    public void SetRotAngle(Vector3 destination)
    {
        dir = (destination - new Vector3(transform.position.x, 0f, transform.position.z));
        float distTotal = dir.magnitude;

        dir /= distTotal;

        rotAngle = SCR_main.GetAngle(new Vector2(transform.position.x, transform.position.z),
                                     new Vector2(destination.x, destination.z));
        rotAngle = (-rotAngle + 90f);
    }
示例#2
0
    void Update()
    {
        if (character.attacking)
        {
            if (!GetComponent <Animation>().IsPlaying(character.animArray[attackAnimSlot]))
            {
                lockActive          = false;
                target              = null;
                attackReady         = true;
                attackBufferAllowed = true;

                if (attackBuffer == false)
                {
                    character.attacking = false;
                    attackCurrent       = 0;

                    if (character.isPlayer == false)
                    {
                        GetComponent <SCR_enemyAI>().SetAction(2);
                    }
                }
            }
        }

        if (attackBuffer && attackReady)
        {
            character.attacking = true;

            attackReady         = false;
            attackBuffer        = false;
            attackBufferAllowed = false;

            if (attackCurrent == 0)
            {
                if (character.running == false)
                {
                    attackAnimSlot = 5;
                    hitTimeCounter = standingAttack_1_hitTime;
                    damage         = standingAttack_1_damage;
                }
                else
                {
                    attackAnimSlot = 7;
                    hitTimeCounter = runningAttack_1_hitTime;
                    damage         = runningAttack_1_damage;
                }
            }

            if (attackCurrent == 1)
            {
                if (character.running == false)
                {
                    attackAnimSlot = 6;
                    hitTimeCounter = standingAttack_2_hitTime;
                    damage         = standingAttack_2_damage;
                }
                else
                {
                    attackAnimSlot = 8;
                    hitTimeCounter = runningAttack_2_hitTime;
                    damage         = runningAttack_2_damage;
                }
            }

            if (character.powerBoost > 0)
            {
                float damageExtra = ((float)damage * ((float)character.powerBoost * 0.01f));
                damage += (int)damageExtra;
            }

            attackSoundCounter = (hitTimeCounter - 0.15f);
            if (attackSoundCounter < 0f)
            {
                attackSoundCounter = 0f;
            }

            character.PlayAnim(attackAnimSlot);

            attackCurrent++;

            if (attackCurrent == attackTotal)
            {
                attackCurrent = 0;
            }

            if (character.isPlayer)
            {
                TargetLock();
            }
        }

        if (hitTimeCounter >= 0f)
        {
            if (attackSoundCounter >= 0f)
            {
                attackSoundCounter -= Time.deltaTime;

                if (attackSoundCounter < 0f)
                {
                    attackSoundCounter = -1f;
                    SCR_main.PlayRandomSound(SND_attack);
                }
            }

            hitTimeCounter -= Time.deltaTime;

            if (hitTimeCounter < 0f)
            {
                hitTimeCounter      = -1f;
                attackBufferAllowed = true;
                AttackHit();
            }
        }

        if (lockActive)
        {
            Vector3 destination = new Vector3(target.transform.position.x, 0f, target.transform.position.z);
            character.dir = (destination - new Vector3(transform.position.x, 0f, transform.position.z));
            float distTotal = character.dir.magnitude;
            character.dir /= distTotal;

            float rotAngle = SCR_main.GetAngle(new Vector2(transform.position.x, transform.position.z),
                                               new Vector2(destination.x, destination.z));
            rotAngle            = (-rotAngle + 90f);
            character.rotTarget = Quaternion.Euler(new Vector3(0f, rotAngle, 0f));
        }
    }