Ejemplo n.º 1
0
 void Update()
 {
     if (weaponInventory.Count > 0)
     { //If these buttons are smashed multiple guns can be spawned, implement a check to see if child count is greater than three and delete anything higher than that.
         if (Input.GetKeyDown("1"))
         {
             activeSlot = 0;
             activeSlot = Mathf.Clamp(activeSlot, 0, weaponInventory.Count - 1);
             if (isPlayer)
             {
                 updateUI.HighlightSlot(activeSlot);
             }
             switchWeapon.Switch(weaponInventory[activeSlot].id);
         }
         if (Input.GetKeyDown("2"))
         {
             activeSlot = 1;
             activeSlot = Mathf.Clamp(activeSlot, 0, weaponInventory.Count - 1);
             if (isPlayer)
             {
                 updateUI.HighlightSlot(activeSlot);
             }
             switchWeapon.Switch(weaponInventory[activeSlot].id);
         }
         if (Input.GetKeyDown("3"))
         {
             activeSlot = 2;
             activeSlot = Mathf.Clamp(activeSlot, 0, weaponInventory.Count - 1);
             if (isPlayer)
             {
                 updateUI.HighlightSlot(activeSlot);
             }
             switchWeapon.Switch(weaponInventory[activeSlot].id);
         }
         if (Input.GetKeyDown("4"))
         {
             activeSlot = 3;
             activeSlot = Mathf.Clamp(activeSlot, 0, weaponInventory.Count - 1);
             if (isPlayer)
             {
                 updateUI.HighlightSlot(activeSlot);
             }
             switchWeapon.Switch(weaponInventory[activeSlot].id);
         }
     }
 }
Ejemplo n.º 2
0
    // Update is called once per frame
    void Update()
    {
        if (done)
        {
            if (mouseFollow.transform.position.x > Player.position.x)
            {
                direction = 6f;
            }
            else
            {
                direction = -6f;
            }
            if (serverRefrenceKeeper.e) //If e is depressed and an object has not already been picked up
            {
                if (deactivated)
                {
                    RealDistance = 20;
                }
                else
                {
                    RealDistance = Vector3.Distance(Weapon.position, Player.position);    //Get distance between player and this
                }
                refrenceKeeper.itemDistanceRefrences[individualCount - 1] = RealDistance; //Update the public list of item distances
                if (RealDistance == 0)
                {
                    RealDistance = 20;
                }
                min = RealDistance;
                for (int i = 0; i < refrenceKeeper.itemDistanceRefrences.Count; i++)
                {
                    if (refrenceKeeper.itemDistanceRefrences[i] < min && refrenceKeeper.itemDistanceRefrences[i] != 0)
                    {
                        min = refrenceKeeper.itemDistanceRefrences[i];
                    }
                }
                if (RealDistance < PickupDistance && RealDistance <= min && serverRefrenceKeeper.e && !deactivated) //If item is within range and it is the closest object and an object hasnt already been picked up
                {
                    serverRefrenceKeeper.e = false;                                                                 //Tell all other scripts an item has been picked up this keypress
                    deactivated            = true;
                    refrenceKeeper.itemDistanceRefrences[individualCount - 1] = 20;                                 //Remove the picked up object from the distances list

                    switchWeapon.Switch(WeaponIndex);

                    if (refrenceKeeper.weaponInventory.Count < 4)
                    {
                        inventoryCount = refrenceKeeper.weaponInventory.Count;
                        refrenceKeeper.weaponInventory.Add(spawnWeapons.Weapons[WeaponIndex].WeaponItem);
                        refrenceKeeper.activeSlot = refrenceKeeper.weaponInventory.Count - 1;
                        updateUI.HighlightSlotOnPickup(refrenceKeeper.activeSlot);
                        updateUI.UpdateSlotsUI();
                    }
                    else
                    {
                        int id = refrenceKeeper.weaponInventory[refrenceKeeper.activeSlot].id;
                        inventoryCount = 3;

                        /*switchedWeapon = Instantiate(gameObject, Player.position, Player.rotation);
                         * switchedWeapon.GetComponent<Pickup>().WeaponIndex = refrenceKeeper.weaponInventory[refrenceKeeper.activeSlot].id;
                         * Destroy(switchedWeapon.transform.GetChild(0).gameObject);
                         * GameObject WeaponModel = Instantiate(
                         *  spawnWeapons.Weapons[refrenceKeeper.weaponInventory[refrenceKeeper.activeSlot].id].WeaponItem.itemModel,
                         *  switchedWeapon.transform.position,
                         *  switchedWeapon.transform.rotation);
                         * WeaponModel.transform.SetParent(switchedWeapon.transform);
                         * WeaponModel.transform.localPosition = new Vector3(0, 0, 0);
                         * switchedWeapon.transform.position = switchedWeapon.transform.position + new Vector3(0, 4, 0);
                         * WeaponModel.gameObject.layer = 11;
                         * switchedWeapon.GetComponent<BulletsLeft>().bullets = shoot.bulletsLeft[refrenceKeeper.activeSlot];
                         * for (int z = 0; z < WeaponModel.transform.childCount; z++)
                         * {
                         *  WeaponModel.transform.GetChild(z).gameObject.layer = 11;
                         * }
                         * switchedWeapon.GetComponent<Pickup>().switchSpawned = true;
                         * switchedWeapon.GetComponent<Pickup>().deactivated = false;
                         * switchedWeapon.transform.SetParent(Items);
                         * localiseTransform.setTransformItem(WeaponModel, refrenceKeeper.weaponInventory[refrenceKeeper.activeSlot].id);*/
                        refrenceKeeper.weaponInventory[refrenceKeeper.activeSlot] = spawnWeapons.Weapons[WeaponIndex].WeaponItem;
                        updateUI.UpdateSlotsUI();
                        updateUI.HighlightSlotOnPickup(refrenceKeeper.activeSlot);
                        GameObject.Find("LocalRelay").GetComponent <SpawnItem>().CmdSpawnDropped(gameObject, Player.position, id, direction, gameObject.GetComponent <BulletsLeft>().bullets);
                    }

                    aimShoot.scale           = spawnWeapons.Weapons[WeaponIndex].WeaponItem.scale;
                    aimShoot.position        = spawnWeapons.Weapons[WeaponIndex].WeaponItem.position;
                    aimShoot.positionFlipped = spawnWeapons.Weapons[WeaponIndex].WeaponItem.positionFlipped;
                    shoot.fireRate           = spawnWeapons.Weapons[WeaponIndex].WeaponItem.fireRate;
                    shoot.recoil             = spawnWeapons.Weapons[WeaponIndex].WeaponItem.recoil;
                    shoot.impact             = spawnWeapons.Weapons[WeaponIndex].WeaponItem.impact;
                    shoot.bulletsLeft[refrenceKeeper.activeSlot] = gameObject.GetComponent <BulletsLeft>().bullets;
                    //Update Stats
                    refrenceKeeper.inventoryCount++;
                    refrenceKeeper.inventoryCount = Mathf.Clamp(refrenceKeeper.inventoryCount, 0, 4);

                    GameObject.Find("LocalRelay").GetComponent <DestroyGun>().CmdDestroyGun(gameObject, individualCount);
                }
            }
        }
    }