Esempio n. 1
0
 // Update is called once per frame
 void Update()
 {
     if (parentOriginalShoot.isPickup)
     {
         return;
     }
     parentAddedShoot.weaponEnabled = parentOriginalShoot.weaponEnabled;
     if (parentOriginalShoot.enabled)
     {
         parentAddedShoot.currentMagazine = parentOriginalShoot.currentMagazine;
         parentAddedShoot.reloaded        = parentOriginalShoot.reloaded;
     }
     else
     {
         parentOriginalShoot.currentMagazine = parentAddedShoot.currentMagazine;
         parentOriginalShoot.reloaded        = parentAddedShoot.reloaded;
     }
     #region Matching all new shoot variables to the original variables
     parentAddedShoot.CopyFrom(parentOriginalShoot, false);
     #endregion
     if (Input.GetButtonDown("Attachment"))       //If player has pressed the attachment use button
     {
         if (Time.time > lastSwitch + switchRate) //if the player is within the switchRate
         {
             lastSwitch = Time.time;
             parentOriginalShoot.enabled = !parentOriginalShoot.enabled; //Switch which shoot is enabled. Only one will be enabled at a time, so they will switch
             parentAddedShoot.enabled    = !parentAddedShoot.enabled;
         }
     }
 }
Esempio n. 2
0
    void ThrowWeapon(GameObject weaponToThrow)
    {
        GameObject tempWeapon = Instantiate(weaponToThrow.GetComponent <PickUpProperties>().actualGunPrefab, weaponSlot.position, weaponSlot.rotation);

        tempWeapon.GetComponent <Rigidbody>().AddForce(4 * weaponSlot.transform.forward, ForceMode.Impulse);
        tempWeapon.GetComponent <Rigidbody>().AddTorque(2 * weaponSlot.transform.up, ForceMode.Impulse);
        Weapon weaponValues = tempWeapon.GetComponent <Weapon>();

        weaponValues.CopyFrom(weaponToThrow.GetComponent <Weapon>());
        weaponValues.isPickup = true;
        if (weaponValues.weaponType == Weapon.WeaponType.Gun)
        {
            Shoot tempShoot = (Shoot)weaponValues;
            tempShoot.CopyFrom(weaponToThrow.GetComponent <Shoot>());
            switch (tempShoot.shootType)
            {
            case Shoot.ShootType.GunShoot:
                GunShoot tempGunShoot = (GunShoot)(tempShoot);
                tempGunShoot.CopyFrom(weaponToThrow.GetComponent <GunShoot>());
                break;

            case Shoot.ShootType.ShotgunShoot:
                ShotgunShoot tempShotgun = (ShotgunShoot)(tempShoot);
                tempShotgun.CopyFrom(weaponToThrow.GetComponent <ShotgunShoot>());
                break;

            case Shoot.ShootType.SemiAutoShoot:
                break;

            case Shoot.ShootType.ChargeShoot:
                ChargeShoot chargeShoot = (ChargeShoot)tempShoot;
                chargeShoot.CopyFrom(weaponToThrow.GetComponent <ChargeShoot>());
                break;

            case Shoot.ShootType.ProjectileShoot:
                break;
            }
        }
        else
        {
            MeleeAttack tempMelee = (MeleeAttack)weaponValues;
            tempMelee.CopyFrom(weaponToThrow.GetComponent <MeleeAttack>());
        }


        Destroy(weaponToThrow);
        UpdateEquippedWeapons();
    }
Esempio n. 3
0
    // Use this for initialization
    void Start()
    {
        FindWeaponParent(transform);
        //Call FindWeaponParent to set the 'parent' Shoot, if it returns false, then stop the rest of Start
        if (parentOriginalShoot != null && !parentOriginalShoot.isPickup)
        {
            parentObject = parentOriginalShoot.gameObject;

            if (!parentObject.GetComponent <BurstShoot>())                       //Check to see if the parent gameObject already has a BurstShoot component attached
            {
                BurstShoot tempShoot = parentObject.AddComponent <BurstShoot>(); //Adding a BurstShoot script to the weapon, and setting tempShoot to it
                tempShoot.bulletsPerBurst = 3;                                   //Setting the bullets per burst of the BurstShoot
                tempShoot.burstFireRate   = .05f;                                //Setting the bursetFireRate of the BurstShoot
                bool increasedMag = false;
                while (parentOriginalShoot.magazineSize % 3 != 0)                //If the original magazine size is not divisible by three, increase it by one until it is (should run only 3 times, max)
                {
                    parentOriginalShoot.magazineSize++;
                    increasedMag = true;
                }
                if (increasedMag)
                {
                    parentOriginalShoot.Reload(true);
                }
                tempShoot.CopyFrom(parentOriginalShoot);     //Copying all the Non-Burst properties into the BurstShoot
                tempShoot.ammo   = parentOriginalShoot.ammo; //Giving the BurstShoot the same ammo object as the original Shoot
                parentAddedShoot = tempShoot;                //Setting parentAddedShoot. The BurstShoot properties won't change, so we don't need to access them anymore
            }
            else //If it does have one attached
            {
                if (parentOriginalShoot.shootType == Shoot.ShootType.BurstShoot)
                //If the parent gameObject is a BurstShoot Object
                {
                    parentAddedShoot = parentObject.AddComponent <SemiAutoShoot>();
                    parentAddedShoot.CopyFrom(parentOriginalShoot);
                    parentAddedShoot.ammo = parentOriginalShoot.ammo;
                }
            }
            parentAddedShoot.enabled    = false;
            parentOriginalShoot.enabled = true;
        }
        else
        {
            Debug.Log("Couldn't find parent with shoot script!");
        }
    }
Esempio n. 4
0
    void Update()
    {
        if ((Input.GetKey(control.pauseMenu) || Input.GetKey(control.inventory)) && isCoroutineRunning)
        {
            gameObject.GetComponent <PauseGame>().HideAttachmentMenu();
            StopCoroutine("AttachWeapon");
            attachmentToAttach = null;
            isCoroutineRunning = false;
        }
        Ray        ray = new Ray(cam.transform.position, cam.transform.forward);
        RaycastHit hit;

        Debug.DrawRay(ray.origin, ray.direction);
        if (Physics.Raycast(ray, out hit, 5))
        {
            if (hit.collider.CompareTag("Chest") || hit.collider.gameObject.GetComponent <ChestContents>())
            {
                useText.SetActive(true);
                chest = hit.collider.GetComponent <ChestContents>();
                useText.GetComponent <Text>().text = chest.ammoChest ? "Pick up Ammo" : "Open Chest";
                if (Input.GetKeyDown(control.use))
                {
                    if (chest.ammoChest)
                    {
                        currentAmmo           = weaponSwitch.equippedWeapon.GetComponent <Weapon>().ammo.GetComponent <Amount>();
                        currentAmmo.amountOf += currentAmmo.limit;
                    }
                    else
                    {
                        pause.ShowChestAndInventory();
                        chestDisplay.SetChestContents(chest);
                        inventoryDisplay.SetOpenChest(chest);
                    }
                }
            }
            else if (hit.collider.gameObject.CompareTag("Weapon"))
            {
                useText.SetActive(true);
                useText.GetComponent <Text>().text = "Pick up " + hit.collider.gameObject.GetComponent <PickUpProperties>().actualGunPrefab.name;

                string weaponName = hit.collider.gameObject.GetComponent <PickUpProperties>().actualGunPrefab.name;

                if (weaponSlot.childCount >= weaponSwitch.maxWeapons)
                {
                    useText.GetComponent <Text>().text = "Replace current weapon with " + weaponName;
                }
                UpdateEquippedWeapons();
                if (Input.GetKeyDown(control.use))
                {
                    if (weaponSlot.childCount >= weaponSwitch.maxWeapons)
                    {
                        GameObject tempWeapon = Instantiate(hit.collider.gameObject.GetComponent <PickUpProperties>().actualGunPrefab, weaponSlot.position, weaponSlot.rotation, weaponSlot);
                        tempWeapon.name = weaponName;

                        equippedWeapons[weaponSwitch.currentWeapon].name   = hit.collider.gameObject.GetComponent <PickUpProperties>().actualGunPrefab.name;
                        equippedWeapons[weaponSwitch.currentWeapon].weapon = tempWeapon;

                        Weapon weaponValues = tempWeapon.GetComponent <Weapon>();
                        weaponValues.CopyFrom(hit.collider.gameObject.GetComponent <Weapon>());

                        if (weaponValues.weaponType == Weapon.WeaponType.Gun)
                        {
                            Shoot tempShoot = (Shoot)weaponValues;
                            tempShoot.CopyFrom(hit.collider.gameObject.GetComponent <Shoot>());
                            switch (tempShoot.shootType)
                            {
                            case Shoot.ShootType.GunShoot:
                                GunShoot gunShoot = (GunShoot)tempShoot;
                                gunShoot.CopyFrom(hit.collider.gameObject.GetComponent <GunShoot>());
                                break;

                            case Shoot.ShootType.ShotgunShoot:
                                ShotgunShoot shotgun = (ShotgunShoot)tempShoot;
                                shotgun.CopyFrom(hit.collider.gameObject.GetComponent <ShotgunShoot>());
                                break;

                            case Shoot.ShootType.SemiAutoShoot:
                                break;

                            case Shoot.ShootType.ChargeShoot:
                                ChargeShoot chargeShoot = (ChargeShoot)tempShoot;
                                chargeShoot.CopyFrom(hit.collider.gameObject.GetComponent <ChargeShoot>());
                                break;

                            case Shoot.ShootType.ProjectileShoot:
                                break;
                            }
                        }
                        else
                        {
                            MeleeAttack tempMelee = (MeleeAttack)weaponValues;
                            tempMelee.CopyFrom(hit.collider.GetComponent <MeleeAttack>());
                        }
                        tempWeapon.transform.SetSiblingIndex(weaponSwitch.currentWeapon);

                        GameObject weaponToDestroy = weaponSlot.GetChild(weaponSwitch.currentWeapon + 1).gameObject;
                        hit.collider.gameObject.GetComponent <MiniMapIndicator>().DestroyCurrentIcon();
                        ThrowWeapon(weaponToDestroy);
                        Destroy(weaponToDestroy);
                        UpdateEquippedWeapons();
                        Destroy(hit.collider.gameObject);
                    }
                    else
                    {
                        GameObject weaponPickedUp = hit.collider.gameObject;
                        GameObject tempWeapon     = Instantiate(weaponPickedUp.GetComponent <PickUpProperties>().actualGunPrefab, weaponSlot.position, weaponSlot.rotation, weaponSlot);
                        tempWeapon.name = weaponName;
                        UpdateEquippedWeapons();
                        Weapon weaponValues = tempWeapon.GetComponent <Weapon>();
                        weaponValues.CopyFrom(weaponPickedUp.GetComponent <Weapon>());
                        weaponValues.isPickup = false;
                        if (weaponValues.weaponType == Weapon.WeaponType.Gun)
                        {
                            Shoot tempShoot = (Shoot)weaponValues;
                            tempShoot.CopyFrom(hit.collider.gameObject.GetComponent <Shoot>());
                            switch (tempShoot.shootType)
                            {
                            case Shoot.ShootType.GunShoot:
                                GunShoot gunShoot = (GunShoot)tempShoot;
                                gunShoot.CopyFrom(hit.collider.gameObject.GetComponent <GunShoot>());
                                break;

                            case Shoot.ShootType.ShotgunShoot:
                                ShotgunShoot shotgun = (ShotgunShoot)tempShoot;
                                shotgun.CopyFrom(hit.collider.gameObject.GetComponent <ShotgunShoot>());
                                break;

                            case Shoot.ShootType.SemiAutoShoot:

                                break;

                            case Shoot.ShootType.ChargeShoot:
                                ChargeShoot chargeShoot = (ChargeShoot)tempShoot;
                                chargeShoot.CopyFrom(hit.collider.gameObject.GetComponent <ChargeShoot>());
                                break;

                            case Shoot.ShootType.ProjectileShoot:
                                break;
                            }
                        }
                        else
                        {
                            MeleeAttack tempMelee = (MeleeAttack)weaponValues;
                            tempMelee.CopyFrom(hit.collider.GetComponent <MeleeAttack>());
                        }

                        weaponSwitch.DisableWeapon(tempWeapon);
                        hit.collider.gameObject.GetComponent <MiniMapIndicator>().DestroyCurrentIcon();
                        Destroy(hit.collider.gameObject);
                    }
                }
            }
            else if (hit.collider.gameObject.CompareTag("Door"))
            {
                Door tempDoor = hit.collider.gameObject.GetComponent <Door>();
                useText.SetActive(true);
                Text text = useText.GetComponent <Text>();
                if (tempDoor.GetIsLocked())
                {
                    bool hasKey = false;
                    int  keyLoc = 0;
                    for (int i = 0; i < keyNumbers.Count; i++)
                    {
                        hasKey = tempDoor.IsCorrectKey(keyNumbers[i]);
                        if (hasKey)
                        {
                            keyLoc = i;
                        }
                    }
                    text.text = (hasKey) ? "Unlock door" : "Door requires key!";

                    if (Input.GetKeyDown(control.use) && hasKey)
                    {
                        tempDoor.UnlockDoor(keyNumbers[keyLoc]);
                        keyNumbers.RemoveAt(keyLoc);
                    }
                }
                else if ((tempDoor.doorType == Door.DoorType.Use || tempDoor.doorType == Door.DoorType.RequiresKeyAfter || tempDoor.doorType == Door.DoorType.RequiresKeyInit) && !tempDoor.isOpen)
                {
                    text.text = "Open door";
                    if (Input.GetKeyDown(control.use))
                    {
                        tempDoor.OpenDoorWithUse();
                    }
                }
                else if (tempDoor.isOpen && tempDoor.doorType == Door.DoorType.Use)
                {
                    text.text = "Close door";
                    if (Input.GetKeyDown(control.use))
                    {
                        tempDoor.CloseDoorWithUse();
                    }
                }
                else
                {
                    useText.SetActive(false);
                }
            }
            else if (hit.collider.gameObject.CompareTag("Key"))
            {
                useText.SetActive(true);
                Text text = useText.GetComponent <Text>();
                text.text = "Pickup key";

                if (Input.GetKeyDown(control.use))
                {
                    try
                    {
                        Key key = hit.collider.gameObject.GetComponent <Key>();
                        keyNumbers.Add(key.keyNumber);
                        Destroy(hit.collider.gameObject);
                    }
                    catch (MissingComponentException e)
                    {
                        Debug.LogException(e);
                    }
                }
            }
            else
            {
                useText.SetActive(false);
            }
        }
        else
        {
            useText.SetActive(false);
        }

        if (Input.GetKeyDown(control.throwWeapon))
        {
            if (weaponSlot.GetChild(weaponSwitch.currentWeapon).gameObject != null)
            {
                ThrowWeapon(weaponSlot.GetChild(weaponSwitch.currentWeapon).gameObject);
                weaponSwitch.SwitchWeaponUp();
            }
            UpdateEquippedWeapons();
        }
    }