public void GivePlayerGun() { GunController controller = null; if ((controller = FindObjectOfType <GunController>()) != null) { controller.AddGun(this); } }
public void PickupItem(Item itm) { pickupSuccessfull = true; switch (itm.itemID) { case ItemID.Rifle: gunController.AddGun(itm.itemID); break; case ItemID.Pistol: gunController.AddGun(itm.itemID); break; case ItemID.Shotgun: gunController.AddGun(itm.itemID); break; case ItemID.RifleAmounition: SetAmounition(itm, ItemID.Rifle); break; case ItemID.PistolAmounition: SetAmounition(itm, ItemID.Pistol); break; case ItemID.ShotgunAmounition: SetAmounition(itm, ItemID.Shotgun); break; case ItemID.HealthPickup: player.AddHealth(itm.giveAmount); break; default: break; } if (pickupSuccessfull) { itm.PickupSuccesfull(); } }
private void Awake() { gunController = GetComponent <GunController>(); controller = GetComponent <PlayerController>(); meleeController = GetComponent <MeleeController>(); inventoryController = GetComponent <PlayerInventoryController>(); viewCamera = Camera.main; FindObjectOfType <Spawner>().OnNewWave += OnNewWave; if (startingGun != null) { gunController.AddGun(startingGun); } else { gunController.AddGun(0); } meleeController.EquippedMeleeWeapon(startingMeleeWeapon); }
//When something collides with this private void OnTriggerEnter(Collider other) { //Check the tag to see if it is a player if (other.gameObject.tag == "Player") { //If so, get the sphere collider of the parent of this and set the GameObject to inactive. SphereCollider parent = this.gameObject.GetComponentInParent <SphereCollider>(); parent.gameObject.SetActive(false); //Check if the player has a general gun controller if (other.transform.GetChild(0).GetComponent <GunController>() != null) { //If it does, store the gunController in the playerInven variable GunController playerInven = other.transform.GetChild(0).GetComponent <GunController>(); //Then add the gun to the inventory based on the itemID. playerInven.AddGun(itemInfo.GetItemID()); } //Checks if the player has a keyboard controller. Previously used for testing. Outdated. else if (other.transform.GetChild(0).GetComponent <KeyboardGunController>() != null) { KeyboardGunController playerInven = other.transform.GetChild(0).GetComponent <KeyboardGunController>(); playerInven.AddGun(itemInfo.GetItemID()); } } }