Example #1
0
    public void PickupItem()
    {
        if (aim.transform.position.x > transform.position.x)
        {
            direction = 12;
        }
        else
        {
            direction = -12f;
        }

        weaponIndex = closestItem.GetComponent <WeaponIndexHolder>().WeaponIndex;

        refrenceKeeper.inventoryCount++;
        refrenceKeeper.inventoryCount = Mathf.Clamp(refrenceKeeper.inventoryCount, 0, 5);

        if (refrenceKeeper.inventoryCount <= 4)
        {
            refrenceKeeper.activeSlot = refrenceKeeper.inventoryCount - 1;
            refrenceKeeper.weaponInventory[refrenceKeeper.activeSlot] = spawnWeapons.Weapons[weaponIndex].WeaponItem;
        }
        else
        {
            if (refrenceKeeper.weaponHeld)
            {
                GetComponent <SpawnItem>().CmdSpawnDropped(weaponItem, transform.position, refrenceKeeper.weaponInventory[refrenceKeeper.activeSlot].id, direction, refrenceKeeper.weaponInventory[refrenceKeeper.activeSlot].currentBullets);
            }
            int id = refrenceKeeper.weaponInventory[refrenceKeeper.activeSlot].id;
            refrenceKeeper.weaponInventory[refrenceKeeper.activeSlot] = spawnWeapons.Weapons[weaponIndex].WeaponItem;
        }
        itemDistanceRefrences.RemoveAt(indexMin);
        items.RemoveAt(indexMin);

        switchWeapon.Switch(weaponIndex);

        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] = closestItem.GetComponent <BulletsLeft>().bullets;
        //Update Stats

        //updateUI.UpdateSlotsUI();
        //updateUI.HighlightSlotOnPickup(refrenceKeeper.activeSlot);
        if (hasAuthority && isPlayer)
        {
            updateUI.UpdateSlotsUI();
            updateUI.HighlightSlotOnPickup(refrenceKeeper.activeSlot);
        }
        RpcPickupWeapon(weaponIndex, closestItem.GetComponent <BulletsLeft>().bullets);

        Destroy(closestItem);

        checkDistances();
    }
Example #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);
                }
            }
        }
    }