Пример #1
0
    private void HandleAimShooting()
    {
        Vector3 targetPosition = UtilsClass.GetMouseWorldPosition();

        playerBase.SetAimTarget(targetPosition);

        if (Input.GetMouseButton(0) && Time.time >= nextShootTime)
        {
            nextShootTime = Time.time + FIRE_RATE;
            playerBase.ShootTarget(targetPosition);
        }
    }
Пример #2
0
    private void FindTarget()
    {
        float targetRange = 160f;
        float attackRange = 50f;

        if (getEnemyTarget != null)
        {
            Vector3 targetPosition = getEnemyTarget().GetPosition();
            if (Vector3.Distance(getEnemyTarget().GetPosition(), GetPosition()) < attackRange)
            {
                StopMoving();
                characterBase.SetAimTarget(targetPosition);

                if (Time.time >= nextShootTime)
                {
                    // Can shoot
                    nextShootTime   = Time.time + FIRE_RATE;
                    targetPosition += GetRandomDir() * UnityEngine.Random.Range(0f, 20f);
                    characterBase.ShootTarget(targetPosition);
                }

                /*
                 * state = State.Attacking;
                 * Vector3 attackDir = (getEnemyTarget().GetPosition() - GetPosition()).normalized;
                 * characterBase.ShootTarget(getEnemyTarget().GetPosition(), () => {
                 *  if (getEnemyTarget() != null) {
                 *      getEnemyTarget().Damage(this);
                 *  }
                 * }, SetStateNormal);
                 */
            }
            else
            {
                if (Vector3.Distance(getEnemyTarget().GetPosition(), GetPosition()) < targetRange)
                {
                    if (pathfindingTimer <= 0f)
                    {
                        pathfindingTimer = .3f;
                        SetTargetPosition(getEnemyTarget().GetPosition());
                    }
                    characterBase.SetAimTarget(targetPosition);
                }
            }
        }
    }
Пример #3
0
    private void HandleAimShooting()
    {
        Vector3 targetPosition = UtilsClass.GetMouseWorldPosition();
        Vector3 aimDir         = (targetPosition - GetPosition()).normalized;

        targetPosition += aimDir * 10f;
        playerBase.SetAimTarget(targetPosition);

        if (Time.time >= nextShootTime)
        {
            // Can shoot
            bool inputActivate = Input.GetMouseButtonDown(0);
            if (weapon.GetWeaponType() == Weapon.WeaponType.Rifle)
            {
                inputActivate = Input.GetMouseButton(0);
            }

            if (inputActivate)
            {
                if (weapon.TrySpendAmmo())
                {
                    nextShootTime = Time.time + weapon.GetFireRate();
                    playerBase.ShootTarget(targetPosition);
                }
                else
                {
                    TryReload();
                }
            }
        }

        if (Input.GetKeyDown(KeyCode.R))
        {
            TryReload();
        }
    }