public void EquipWeapon(Weapon.Weapons weaponToEquip) { if (weaponToEquip == weaponInHand) { return; } if (hand.childCount > 0) { Transform temp = hand.GetChild(0); if (temp != null) { Destroy(temp.gameObject); } equippedWeapon = null; } if (weaponToEquip == Weapon.Weapons.Nothing) { } else { GameObject prefabToSpawn = gameController.weaponPrefabs[(int)weaponToEquip]; GameObject newWeapon = Instantiate(prefabToSpawn, Vector3.zero, hand.rotation) as GameObject; newWeapon.transform.parent = hand; newWeapon.transform.localPosition = Vector3.zero; newWeapon.transform.localRotation = hand.localRotation; switch ((int)weaponToEquip) { //Raygun case 0: equippedWeapon = GetComponentInChildren <Weapon_Raygun>(); break; //Blaster case 1: equippedWeapon = GetComponentInChildren <Weapon_Blaster>(); break; //Grenade Launcher case 2: equippedWeapon = GetComponentInChildren <Weapon_GrenadeLauncher>(); break; case 3: equippedWeapon = GetComponentInChildren <Weapon_Pistol>(); break; } equippedWeapon.teamToHit = GameController.Teams.Enemy; foreach (Transform t in newWeapon.GetComponentsInChildren <Transform>()) { t.gameObject.layer = LayerMask.NameToLayer("Weapon"); } weaponInHand = weaponToEquip; } }
public void Initialise(Weapon.Weapons pickup) { if (pickup == Weapon.Weapons.Nothing) Destroy(gameObject); this.pickup = pickup; weaponPrefab = GameController.Instance.weaponPrefabs[(int)pickup]; weapon = Instantiate(weaponPrefab, spawnLocation.position, Quaternion.identity) as GameObject; weapon.transform.parent = spawnLocation; weapon.transform.localPosition = new Vector3(0, 0, 0); }
public void Initialise(Weapon.Weapons pickup) { if (pickup == Weapon.Weapons.Nothing) { Destroy(gameObject); } this.pickup = pickup; weaponPrefab = GameController.Instance.weaponPrefabs[(int)pickup]; weapon = Instantiate(weaponPrefab, spawnLocation.position, Quaternion.identity) as GameObject; weapon.transform.parent = spawnLocation; weapon.transform.localPosition = new Vector3(0, 0, 0); }
// Use this for initialization void Start() { weaponInHand = Weapon.Weapons.Nothing; lifeManager = GetComponent <LifeManager_Player>(); ioManager = GetComponent <InteractionManager>(); gameController = GameController.Instance; EquipWeapon(startWeapon); lifeManager.onDamage += Hit; lifeManager.onDeath += Death; audioSource = GetComponent <AudioSource>(); Cursor.lockState = CursorLockMode.Locked; Cursor.visible = false; animator = GetComponent <Animator>(); fpsController = GetComponent <FirstPersonController>(); charController = GetComponent <CharacterController>(); StartCoroutine(ScaleFov(true, 0.5f)); }
public void EquipWeapon(Weapon.Weapons weaponToEquip) { if (weaponToEquip == weaponInHand) return; if (hand.childCount > 0) { Transform temp = hand.GetChild(0); if (temp != null) Destroy(temp.gameObject); equippedWeapon = null; } if (weaponToEquip == Weapon.Weapons.Nothing) { } else { GameObject prefabToSpawn = gameController.weaponPrefabs[(int)weaponToEquip]; GameObject newWeapon = Instantiate(prefabToSpawn, Vector3.zero, hand.rotation) as GameObject; newWeapon.transform.parent = hand; newWeapon.transform.localPosition = Vector3.zero; newWeapon.transform.localRotation = hand.localRotation; switch ((int)weaponToEquip) { //Raygun case 0: equippedWeapon = GetComponentInChildren<Weapon_Raygun>(); break; //Blaster case 1: equippedWeapon = GetComponentInChildren<Weapon_Blaster>(); break; //Grenade Launcher case 2: equippedWeapon = GetComponentInChildren<Weapon_GrenadeLauncher>(); break; case 3: equippedWeapon = GetComponentInChildren<Weapon_Pistol>(); break; } equippedWeapon.teamToHit = GameController.Teams.Enemy; foreach (Transform t in newWeapon.GetComponentsInChildren<Transform>()) { t.gameObject.layer = LayerMask.NameToLayer("Weapon"); } weaponInHand = weaponToEquip; } }
// Use this for initialization void Start() { weaponInHand = Weapon.Weapons.Nothing; lifeManager = GetComponent<LifeManager_Player>(); ioManager = GetComponent<InteractionManager>(); gameController = GameController.Instance; EquipWeapon(startWeapon); lifeManager.onDamage += Hit; lifeManager.onDeath += Death; audioSource = GetComponent<AudioSource>(); Cursor.lockState = CursorLockMode.Locked; Cursor.visible = false; animator = GetComponent<Animator>(); fpsController = GetComponent<FirstPersonController>(); charController = GetComponent<CharacterController>(); StartCoroutine(ScaleFov( true, 0.5f)); }
public void PickupWeapon(Weapon.Weapons weapon) { EquipWeapon(weapon); audioSource.PlayOneShot(weapon_Pickup, 0.8f); }