void Weapons() { int active = -1 + (Input.GetKeyDown(KeyCode.Alpha1) ? 1 : 0) + 2 * (Input.GetKeyDown(KeyCode.Alpha2) ? 1 : 0) + 3 * (Input.GetKeyDown(KeyCode.Alpha3) ? 1 : 0); if (active > -1 && active < 3) { if (!handsWeaponsManager.weapons[active].activeInHierarchy) { for (int i = 0; i < handsWeaponsManager.weapons.Length; i++) { handsWeaponsManager.weapons[i].SetActive(false); } handsWeaponsManager.weapons[active].SetActive(true); handsWeapon = handsWeaponsManager.weapons[active].GetComponent <FPSHands>(); } if (!weaponsManager.weapons[active].activeInHierarchy) { for (int i = 0; i < weaponsManager.weapons.Length; i++) { weaponsManager.weapons[i].SetActive(false); } weaponsManager.weapons[active].SetActive(true); weapon = weaponsManager.weapons[active].GetComponent <FPSWeapon>(); anims.ChangeController((active == 0) ? true : false); nextTimeToFire = Time.time + 1.25f; } } }
void Start() { view = transform.Find("FPS View").transform; controller = GetComponent <CharacterController>(); shooter = GetComponent <FPSShooting>(); anims = GetComponent <FPSAnimations>(); speed = walkSpeed; moving = false; rayDistance = controller.height * 0.5f + controller.radius; defaultHeight = controller.height; defaultCamPos = view.localPosition; nextTimeToFire = Time.time + 1.25f; weaponsManager.weapons[0].SetActive(true); weapon = weaponsManager.weapons[0].GetComponent <FPSWeapon>(); handsWeaponsManager.weapons[0].SetActive(true); handsWeapon = handsWeaponsManager.weapons[0].GetComponent <FPSHands>(); playerHolder.layer = LayerMask.NameToLayer(isLocalPlayer ? "Player" : "Default"); foreach (Transform child in playerHolder.transform) { child.gameObject.layer = LayerMask.NameToLayer(isLocalPlayer ? "Player" : "Default"); } for (int i = 0; i < weapons.Length; i++) { weapons[i].layer = LayerMask.NameToLayer(isLocalPlayer ? "Player" : "Default"); } weaponsHolder.layer = LayerMask.NameToLayer(isLocalPlayer ? "Default" : "Player"); foreach (Transform child in weaponsHolder.transform) { child.gameObject.layer = LayerMask.NameToLayer(isLocalPlayer ? "Default" : "Player"); } if (!isLocalPlayer) { for (int i = 0; i < mouseLook.Length; i++) { mouseLook[i].enabled = false; } } transform.Find("FPS View").Find("FPS Camera").gameObject.SetActive(isLocalPlayer); }