public override void interact()
    {
        base.interact();
        GunPlaceHolderPlayer holder = gameManager.player.GetComponentInChildren <GunPlaceHolderPlayer>();
        GameObject           c      = Instantiate(creator, transform.position, transform.rotation);
        pupCreater           create = c.GetComponent <pupCreater>();
        bool replacing;

        if (holder.activePrimary == id)
        {
            replacing = false;
        }
        else
        {
            replacing = true;
            /////
            gun g = holder.findWeaponByID(holder.activePrimary).GetComponent <gun>();

            create.id   = g.id;
            create.ammo = g.ammoInBag + g.ammoInMag;
            g.ammoInMag = 0;
        }
        holder.activePrimary = id;
        if (holder.holdingPrimary)
        {
            holder.switchWeapon();
            holder.switchWeapon();
        }
        else
        {
            holder.switchWeapon();
        }
        if (replacing)
        {
            holder.ActiveGun.GetComponent <gun>().ammoInBag = ammo;
            create.Create();
        }
        else
        {
            holder.ActiveGun.GetComponent <gun>().ammoInBag += ammo;
        }
        Destroy(gameObject);
    }
Beispiel #2
0
    void Drop()
    {
        Vector3     dropPosition = new Vector3(transform.position.x, transform.position.y, transform.position.z + Random.Range(-spawnRange, spawnRange));
        gameManager manager      = GameObject.Find("GameManager").GetComponent <gameManager>();

        if (Random.Range(0f, 1f) < healthAndShieldDropChance)
        {
            GameObject hs  = Instantiate(drop, dropPosition, transform.rotation);
            pupCreater pup = hs.GetComponent <pupCreater>();
            if (Random.Range(0, 2) == 0)
            {
                pup.health       = true;
                pup.healthAmount = manager.healthRecharge_;
            }
            else
            {
                pup.shield       = true;
                pup.shieldAmount = manager.shieldRecharge_;
            }
            pup.Create();
        }
        float chance = Random.Range(0f, 1f);

        if (chance < WeaponDropChance)
        {
            GameObject hs  = Instantiate(drop, dropPosition, transform.rotation);
            pupCreater pup = hs.GetComponent <pupCreater>();
            if (Random.Range(0f, 1f) < UsingWeaponDropChance)
            {
                int Gunid = gameManager.player.GetComponentInChildren <GunPlaceHolderPlayer>().activePrimary;
                pup.id = Gunid;
                int type = Gunid % 10;
                pup.ammo = manager.AmmoRechargePrimary[type];
            }
            else
            {
                int choice   = Random.Range(0, 5);
                int variant  = Random.Range(0, 3);
                int ammoFill = 0;
                int type     = 0;
                int id       = 0;
                if (choice != 0)
                {
                    type     = Random.Range(0, 5);
                    id       = 200 + variant * 10 + type;
                    ammoFill = manager.AmmoRechargePrimary[type];
                }
                else
                {
                    type     = 0;
                    id       = 100 + variant * 10 + type;
                    ammoFill = manager.ammorechargeSecondary[type];
                }
                pup.id   = id;
                pup.ammo = ammoFill;
            }
            pup.Create();
        }
        chance = Random.Range(0f, 1f);
        if (chance < grenadeDropChance)
        {
            GameObject hs       = Instantiate(drop, dropPosition, transform.rotation);
            pupCreater pup      = hs.GetComponent <pupCreater>();
            int        type     = Random.Range(0, 3);
            int        id       = 300 + type;
            int        ammoFill = manager.rechargeGrenades[type];
            pup.id   = id;
            pup.ammo = ammoFill;
            pup.Create();
        }
    }