예제 #1
0
    public void ArcadeMode()
    {
        EnterExitCar EnterExit = FindObjectOfType <EnterExitCar>();

        EnterExit.PlayingArcadeMode = true;
        PlayerWeapons weapons = FindObjectOfType <PlayerWeapons>();

        TutorialInstructions.text = "Shoot at enemies with gun";
        weapons.firstWeapon       = 5;
        weapons.weaponOrder[5].GetComponent <WeaponBehavior>().haveWeapon = true;
        StartCoroutine(weapons.SelectWeapon(5));
    }
예제 #2
0
    public void PickUpItem()
    {
        //if player has less than max ammo for this weapon, give player ammoToAdd amount
        if (WeaponBehaviorComponent.ammo < WeaponBehaviorComponent.maxAmmo)
        {
            if (WeaponBehaviorComponent.ammo + ammoToAdd > WeaponBehaviorComponent.maxAmmo)
            {
                //just give player max ammo if they only are a few bullets away from having max ammo
                WeaponBehaviorComponent.ammo = WeaponBehaviorComponent.maxAmmo;
            }
            else
            {
                //give player the ammoToAdd amount
                WeaponBehaviorComponent.ammo += ammoToAdd;
            }

            //play pickup sound
            if (pickupSound)
            {
                PlayAudioAtPos.PlayClipAt(pickupSound, myTransform.position, 0.75f);
            }

            //equip/activate weapon if we picked up ammo for disposable, one-shot weapon like grenades
            if (!WeaponBehaviorComponent.doReload && !WeaponBehaviorComponent.haveWeapon && !WeaponBehaviorComponent.nonReloadWeapon)
            {
                WeaponBehaviorComponent.haveWeapon = true;
                PlayerWeaponsComponent.StartCoroutine(PlayerWeaponsComponent.SelectWeapon(WeaponBehaviorComponent.weaponNumber));
            }

            if (removeOnUse)
            {
                FreePooledObjects();
                if (objectPoolIndex == 0)
                {
                    //remove this weapon pickup
                    Object.Destroy(gameObject);
                }
                else
                {
                    AzuObjectPool.instance.RecyclePooledObj(objectPoolIndex, myTransform.gameObject);
                }
            }
        }
        else
        {
            //if player is at max ammo, just play beep sound
            if (fullSound)
            {
                PlayAudioAtPos.PlayClipAt(fullSound, myTransform.position, 0.75f);
            }
        }
    }
예제 #3
0
    public void StealthMode()
    {
        EnterExitCar EnterExit = FindObjectOfType <EnterExitCar>();

        EnterExit.ExitCar         = true;
        EnterExit.whatToDo.text   = "";
        TutorialInstructions.text = "Walk Slowly and attack enemies from behind";
        TutorialInstructions.gameObject.SetActive(true);
        EnterExit.enabled = false;
        PlayerWeapons weapons = FindObjectOfType <PlayerWeapons>();

        weapons.firstWeapon = 1;
        weapons.weaponOrder[1].GetComponent <WeaponBehavior>().haveWeapon = true;
        StartCoroutine(weapons.SelectWeapon(1));
        ExitCar();
    }
예제 #4
0
    void PickUpItem()
    {
        //find the PlayerWeapons script in the FPS Prefab to access weaponOrder array
        PlayerWeapons  PlayerWeaponsComponent         = Camera.main.transform.GetComponent <CameraKick>().weaponObj.GetComponent <PlayerWeapons>();
        WeaponBehavior WeaponBehaviorComponent        = weaponObj.GetComponent <WeaponBehavior>();
        WeaponBehavior CurrentWeaponBehaviorComponent = PlayerWeaponsComponent.weaponOrder[PlayerWeaponsComponent.currentWeapon].GetComponent <WeaponBehavior>();

        //if player does not have this weapon, pick it up
        if (!WeaponBehaviorComponent.haveWeapon)
        {
            //if the player is at max weapons and this weapon takes up an inventory space, drop the current weapon before equipping this one
            if (PlayerWeaponsComponent.totalWeapons == PlayerWeaponsComponent.maxWeapons && WeaponBehaviorComponent.addsToTotalWeaps)
            {
                //determine if this weapon can be dropped (weapons like fists or a sidearm can be set to not be droppable)
                if (CurrentWeaponBehaviorComponent.droppable)
                {
                    //drop current weapon if dropCurrentWeapon is true
                    if (removeOnUse && !WeaponBehaviorComponent.dropWillDupe && !CurrentWeaponBehaviorComponent.dropWillDupe)
                    {
                        PlayerWeaponsComponent.DropWeapon(PlayerWeaponsComponent.currentWeapon);
                    }
                    else                      //replace current weapon if dropCurrentWeapon is false
                    {
                        CurrentWeaponBehaviorComponent.haveWeapon   = false;
                        CurrentWeaponBehaviorComponent.dropWillDupe = false;
                        //prevent dropping this weapon and creating duplicated ammo by picking up the weapon again from the non-destroyable pickup item
                        WeaponBehaviorComponent.dropWillDupe = true;
                    }
                }
                else                  //currently held weapon is not dropable, so find next item in the weaponOrder array that is droppable, and drop it

                {
                    for (int i = PlayerWeaponsComponent.currentWeapon; i < PlayerWeaponsComponent.weaponOrder.Length; i++)
                    {
                        if (PlayerWeaponsComponent.weaponOrder[i].GetComponent <WeaponBehavior>().haveWeapon &&
                            PlayerWeaponsComponent.weaponOrder[i].GetComponent <WeaponBehavior>().droppable)
                        {
                            weaponToDrop = i;                            //found the weapon to drop, break loop
                            break;
                            //no weapon found to drop counting up from current weapon number in weaponOrder array, so start at zero and count upwards
                        }
                        else if (i == PlayerWeaponsComponent.weaponOrder.Length - 1)
                        {
                            for (int n = 0; n < PlayerWeaponsComponent.weaponOrder.Length; n++)
                            {
                                if (PlayerWeaponsComponent.weaponOrder[n].GetComponent <WeaponBehavior>().haveWeapon &&
                                    PlayerWeaponsComponent.weaponOrder[n].GetComponent <WeaponBehavior>().droppable)
                                {
                                    weaponToDrop = n;
                                    break;                                    //found the weapon to drop, break loop
                                }
                            }
                        }
                    }

                    if (removeOnUse && !WeaponBehaviorComponent.dropWillDupe)                    //drop the next weapon if dropCurrentWeapon is true and current weapon is not droppable
                    {
                        PlayerWeaponsComponent.DropWeapon(weaponToDrop);
                    }
                    else                      //replace the next weapon if dropCurrentWeapon is false and current weapon is not droppable
                    {
                        PlayerWeaponsComponent.weaponOrder[weaponToDrop].GetComponent <WeaponBehavior>().haveWeapon   = false;
                        PlayerWeaponsComponent.weaponOrder[weaponToDrop].GetComponent <WeaponBehavior>().dropWillDupe = false;
                        //prevent dropping this weapon and creating duplicated ammo by picking up the weapon again from the non-destroyable pickup item
                        WeaponBehaviorComponent.dropWillDupe = true;
                    }
                }
            }

            //update haveWeapon value of new weapon's WeaponBehavior.cs component
            WeaponBehaviorComponent.haveWeapon = true;
            if (!removeOnUse)
            {
                WeaponBehaviorComponent.dropWillDupe = true;
            }
            else
            {
                WeaponBehaviorComponent.dropWillDupe = false;
            }
            //select the weapon after picking it up
            PlayerWeaponsComponent.StartCoroutine(PlayerWeaponsComponent.SelectWeapon(WeaponBehaviorComponent.weaponNumber));
            //update the total weapon amount in PlayerWeapons.cs
            PlayerWeaponsComponent.UpdateTotalWeapons();
            //remove pickup item from game world and play sound
            RemovePickup();
        }
        else          //the player already has this weapon, so give them ammo instead

        {
            if ((WeaponBehaviorComponent.ammo < WeaponBehaviorComponent.maxAmmo && removeOnUse) &&         //player is not carrying max ammo for this weapon
                WeaponBehaviorComponent.meleeSwingDelay == 0)             //player is not trying to pick up a melee weapon they already have

            {
                if (WeaponBehaviorComponent.ammo + WeaponBehaviorComponent.bulletsPerClip > WeaponBehaviorComponent.maxAmmo)
                {
                    //just give player max ammo if they only are a few bullets away from having max ammo
                    WeaponBehaviorComponent.ammo = WeaponBehaviorComponent.maxAmmo;
                }
                else
                {
                    //give player the bulletsPerClip amount if they already have this weapon
                    WeaponBehaviorComponent.ammo += WeaponBehaviorComponent.bulletsPerClip;
                }

                RemovePickup();                //remove pickup item from game world and play sound
            }
            else
            {
                //if player has weapon and is at max ammo, just play beep sound
                if (fullSound)
                {
                    AudioSource.PlayClipAtPoint(fullSound, myTransform.position, 0.75f);
                }
            }
        }
    }