Beispiel #1
0
    public void OnTriggerStay2D(Collider2D collision)
    {
        if (Input.GetKeyDown(KeyCode.E))                   //when e pressed   collision.gameObject.name == "Player"
        {
            if (collision.gameObject.CompareTag("Player")) //when player enters an item drop
            {
                Mob playerMob = collision.gameObject.GetComponent <Mob>();
                Weapons_Module.Weapon weaponToGive = Weapons_Module.GetWeapon(weaponToDropName, playerMob.bulletSource);
                int weaponToDropTier = weaponToGive.tier;
                playerMob.DropWeapon(weaponToDropTier - 1);
                playerMob.GiveWeapon(weaponToGive);
                GameObject.Destroy(this.gameObject);



                /*
                 * GameObject OwnWeaponDrop;
                 * OwnWeaponDrop = Instantiate(gameObject, player.transform.position, Quaternion.identity);
                 * int Index = gameObject.GetComponent<Player_Control>().currentWeaponIndex;
                 * OwnWeaponDrop.GetComponent<GiveWeapon>().weaponname = collision.gameObject.GetComponent<Mob>().Inventory[Index].name;
                 *
                 * Debug.Log("dropping " + gameObject.GetComponent<GiveWeapon>().weaponname);
                 *
                 * Debug.Log("giving " + weaponname);
                 * collision.gameObject.GetComponent<Mob>().Inventory[Weapons_Module.GetWeapon(weaponname, collision.gameObject.GetComponent<Mob>().bulletSource).tier - 1] = Weapons_Module.GetWeapon(weaponname, collision.gameObject.GetComponent<Mob>().bulletSource);
                 * Destroy(gameObject);
                 */
            }
        }
    }
Beispiel #2
0
 public void DropWeapon(int inventorySlot)
 {
     if (Inventory[inventorySlot] != null)
     {
         GameObject droppedWeapon = Instantiate(Weapons_Module.droppedWeaponPrefab, gameObject.transform.position, Quaternion.identity);
         droppedWeapon.GetComponent <SpriteRenderer>().sprite         = Weapons_Module.GetWeaponSprite(Inventory[inventorySlot].name);
         droppedWeapon.GetComponent <WeaponPickup>().weaponToDropName = Inventory[inventorySlot].name;
         droppedWeapon.tag = "Pickup";
     }
 }
Beispiel #3
0
    private void Start()
    {
        timeLastSelfDamagePerSecond = Time.time;
        if (InventorySize > 0)
        {
            Inventory = new Weapons_Module.Weapon[InventorySize];
        }

        if (startingWeaponStr != null)
        {
            Inventory[0]  = Weapons_Module.GetWeapon(startingWeaponStr, bulletSource);
            currentWeapon = Inventory[0];
        }
        else
        {
            Inventory[0] = Weapons_Module.GetWeapon("Nothing1", bulletSource);
        }

        if (secondWeaponStr != null)
        {
            Inventory[1] = Weapons_Module.GetWeapon(secondWeaponStr, bulletSource);
        }
        else if (InventorySize > 1)
        {
            Inventory[1] = Weapons_Module.GetWeapon("Nothing2", bulletSource);
        }

        if (thirdWeaponStr != null)
        {
            Inventory[2] = Weapons_Module.GetWeapon(thirdWeaponStr, bulletSource);
        }
        else if (InventorySize > 1)
        {
            Inventory[2] = Weapons_Module.GetWeapon("Nothing3", bulletSource);
        }
    }
Beispiel #4
0
    void Update()
    {
        //This controls the grey highlight over the Weapon Bar
        int Index = gameObject.GetComponentInParent <Mob>().GetCurrentWeaponIndex();

        if (Index == 0)
        {
            float x = Slot1.transform.position.x;
            float y = Slot1.transform.position.y;
            float z = Slot1.transform.position.z;
            SelectVisualizer.transform.position = new Vector3(x, y, z);
        }
        else if (Index == 1)
        {
            float x = Slot2.transform.position.x;
            float y = Slot2.transform.position.y;
            float z = Slot2.transform.position.z;
            SelectVisualizer.transform.position = new Vector3(x, y, z);
        }
        else if (Index == 2)
        {
            float x = Slot3.transform.position.x;
            float y = Slot3.transform.position.y;
            float z = Slot3.transform.position.z;
            SelectVisualizer.transform.position = new Vector3(x, y, z);
        }


        //This ensures that the weapon picked up is equipped to the correct slot
        foreach (Weapons_Module.Weapon Gun in gameObject.GetComponentInParent <Mob>().Inventory)
        {
            if (Gun != null)
            {
                if (Gun.tier == 1)
                {
                    Slot1.sprite = Weapons_Module.GetWeaponSprite(Gun.name);
                }

                else if (Gun.tier == 2)
                {
                    Slot2.sprite = Weapons_Module.GetWeaponSprite(Gun.name);
                }

                else if (Gun.tier == 3)
                {
                    Slot3.sprite = Weapons_Module.GetWeaponSprite(Gun.name);
                }
            }



            /*
             * if (Gun.name=="Pistol") { Slot1.sprite = Weapons_Module.GetWeaponSprite("Pistol"); }
             * else if (Gun.name=="Uzi") { Slot1.sprite = Weapons_Module.GetWeaponSprite("Uzi"); }
             * else if (Gun.name== "Revolver") { Slot1.sprite = Weapons_Module.GetWeaponSprite("Revolver"); }
             * else if (Gun.name== "Knife") { Slot1.sprite = Weapons_Module.GetWeaponSprite("Knife"); }
             * else if (Gun.name== "Shotgun") { Slot2.sprite = Weapons_Module.GetWeaponSprite("Shotgun"); }
             * else if (Gun.name== "AK47") { Slot3.sprite = Weapons_Module.GetWeaponSprite("AK47"); }
             * else if (Gun.name== "M40"|| Gun.name == "M16") {Slot2.sprite = Weapons_Module.GetWeaponSprite("M16"); }
             */
        }
    }