Пример #1
0
    public override void Update()
    {
        base.Update();

        // Get collection of other cars transforms (so their position can be tracked)
        if (cars == null)
        {
            cars = GameObject.FindGameObjectsWithTag("Car").Select(go => go.transform).Where(t => t != car.transform);
        }

        // Order cars by distance from this car
        cars.OrderBy(t => Vector3.Distance(car.transform.position, t.position));

        // If the closest car is not the car currently being chased
        if (cars.First() != target)
        {
            target = cars.First();       // Overwrite ref to closest car
            ai.Follow(target);           // Chase new closest car
        }

        // Out of ammo, find another power up
        if (launcher.nRemainingMissiles == 0)
        {
            ai.SetState(new FindPowerUp(ai, car));
        }

        // Target in firing arc... ANNIHILATE!
        if (InCrosshair(target.position))
        {
            launcher.Shoot();
        }
    }
Пример #2
0
    private void shootControls()
    {
        if (Input.GetMouseButton(0))
        {
            machineGun.Shoot(aSource, mousePos);
        }

        if (Input.GetMouseButtonDown(1))
        {
            rocketLauncher.Shoot(aSource, mousePos);
        }
    }
Пример #3
0
    void Update()
    {
        if (Game.Instance.EnemyTimeScale == 0)
        {
            return;
        }

        if (Body.Ragdolled && !isDead)
        {
            return;
        }
        if (isDead)
        {
            if (!WaitAfterDeadTimer.Finished)
            {
                if (WaitAfterDeadTimer.Update())
                {
                    SetCollider(false);
                }
                UpdateRenderColor();
            }
            return;
        }

        if (WayCheckTimer.Update())
        {
            SomeoneInMyWay = false;
            WayCheckTimer.Reset();
            RaycastHit hit;
            if (Physics.Raycast(EyePosition.position, WalkDirection, out hit, ObstacleDistance, ObstacleLayer))
            {
                if (!myChildren.Contains(hit.transform))
                {
                    SomeoneInMyWay = true;
                }
            }
        }

        if (FindTargetTimer.Update())
        {
            FindTargetTimer.Reset();
            FindTarget();
        }
        if (HasTarget)
        {
            CanSeeTarget = false;
            RaycastHit hit;
            if (Physics.Raycast(EyePosition.position, (Target.position - EyePosition.position).normalized, out hit, SightRange, playerSight))
            {
                if (hit.transform == Target)
                {
                    CanSeeTarget  = true;
                    LastTargetPos = TargetPosition;
                }
            }
            if (!CanSeeTarget)
            {
                Target = null;
                TargetChanged();
            }
        }
        else
        {
            CanSeeTarget = false;
        }
        if (UpdateTargetTimer.Update())
        {
            UpdateTargetTimer.Reset();
            UpdateTarget();
        }
        if (ShootTimer.Update())
        {
            if (CanSeeTarget && TargetInAttackRange && !Body.Ragdolled)
            {
                if (weapon && weapon.Shoot(CurrentDamage))
                {
                    ShootTimer.Reset();
                }
            }
        }
    }