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); */ } } }
public void GiveWeapon(Weapons_Module.Weapon weapon) { int weaponToGiveTier = weapon.tier; int currentWeaponIndex = GetCurrentWeaponIndex(); Inventory[weaponToGiveTier - 1] = weapon; currentWeapon = Inventory[currentWeaponIndex]; /* * if(weaponToGiveTier-1 == currentWeaponIndex) * { * Debug.Log("HOUSTON WE HAVE A PROBLEM!"); * currentWeapon = Inventory[weaponToGiveTier - 1]; * try * { * currentWeapon = Inventory[weaponToGiveTier]; * } * catch * { * currentWeapon = Inventory[weaponToGiveTier+1]; * } * } */ }
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); } }