void DesktopController()
        {
            // Desktop controller
            flight.SimpleControl = SimpleControl;

            // lock mouse position to the center.
            MouseLock.MouseLocked = true;

            flight.AxisControl(new Vector2(Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y")));

            if (SimpleControl)
            {
                flight.TurnControl(Input.GetAxis("Mouse X"));
            }

            flight.TurnControl(Input.GetAxis("Horizontal"));
            flight.SpeedUp(Input.GetAxis("Vertical"));


            if (Input.GetButton("Fire1"))
            {
                flight.WeaponControl.LaunchWeapon();
            }

            if (Input.GetButtonDown("Fire2"))
            {
                flight.WeaponControl.SwitchWeapon();
            }

            if (Input.GetKeyDown(KeyCode.C))
            {
                if (View)
                {
                    View.SwitchCameras();
                }
            }
        }
Beispiel #2
0
        bool shootTarget(Vector3 targetPos)
        {
            // Shooting ...
            // checking direction between Target and AI
            Vector3 dir = (targetPos - transform.position).normalized;

            dot = Vector3.Dot(dir, transform.forward);
            // checking distance between Target and AI
            float distance = Vector3.Distance(targetPos, this.transform.position);

            if (distance <= DistanceAttack)              // is in Range ?
            // Ok in range

            {
                if (dot >= AttackDirection)                  // is in Direction ?
                // Ok Can Shoot them.

                {
                    attacking = true;
                    if (Random.Range(0, 100) <= AttackRate)                 // Make it delay and unstable shooting by Attack rate (if you set Attack Rate to 100 this AI will alway shooting like a brutal)
                    {
                        flight.WeaponControl.LaunchWeapon(WeaponSelected);  // FIRE A GUN!!!
                    }
                    if (distance < DistanceAttack / 3)                      // if too close the target , let's turning back a while.
                    {
                        turnPosition();
                    }
                }
                else
                {
                    // cannot shoot.
                    // random weapon in flight.WeaponControl.WeaponLists
                    WeaponSelected = Random.Range(0, flight.WeaponControl.WeaponLists.Length);
                    return(false);
                }
            }
            else
            {
                // cannot shoot. the target is too far!! let moving faster!!
                flight.SpeedUp();
            }
            return(true);
        }