private void Fire() { //If theres no Gun dont shoot if (gunControllScript.noGun.activeSelf) { return; } else { if (cooldown > 0 || ammo <= 0) { return; } if (gunName != "") { m_Animator.SetTrigger("CanShoot" + gunName); } ammo -= 1; //If no ammo while shooting - Reload if (ammo <= 0) { gunControllScript.Reload(); return; } RaycastHit objectHit; // Shoot raycast if (Physics.Raycast(bulletSpawn.transform.position, bulletSpawn.transform.forward, out objectHit, range)) { Health h = objectHit.collider.GetComponent <Health> (); if (fxManager != null) { Vector3 endPoint; endPoint = objectHit.point; crossHair.transform.position = endPoint; fxManager.GetComponent <PhotonView> ().RPC("BulletFx", PhotonTargets.All, bulletSpawn.transform.position, endPoint); PhotonNetwork.Instantiate(Particals.name, bulletSpawn.transform.position, bulletSpawn.transform.rotation, 0); } if (h != null) { PhotonPlayer playerHit = objectHit.collider.GetComponent <PhotonView> ().owner; if (PhotonNetwork.player.GetTeam() == playerHit.GetTeam()) { Debug.Log("Friendly Fire"); } else { h.GetComponent <PhotonView>().RPC("TakeDamage", PhotonTargets.All, damage); if (objectHit.collider.gameObject.GetComponent <Health>().canAddScore&& objectHit.collider.gameObject.GetComponent <Health>().isKilled) { PhotonNetwork.player.AddScore(1); if (PhotonNetwork.player.GetTeam() == PunTeams.Team.blue && (int)PhotonNetwork.room.CustomProperties ["FlagSide"] == 1) { PhotonNetwork.room.SetCustomProperties(new ExitGames.Client.Photon.Hashtable() { { "BlueScore", (int)PhotonNetwork.room.CustomProperties["BlueScore"] + 1 } }); Debug.Log("blue: " + PhotonNetwork.room.CustomProperties ["BlueScore"] + " Red: " + PhotonNetwork.room.CustomProperties ["RedScore"]); } else if (PhotonNetwork.player.GetTeam() == PunTeams.Team.red && (int)PhotonNetwork.room.CustomProperties ["FlagSide"] == 2) { PhotonNetwork.room.SetCustomProperties(new ExitGames.Client.Photon.Hashtable() { { "RedScore", (int)PhotonNetwork.room.CustomProperties["RedScore"] + 1 } }); Debug.Log("blue: " + PhotonNetwork.room.CustomProperties ["BlueScore"] + " Red: " + PhotonNetwork.room.CustomProperties ["RedScore"]); } objectHit.collider.gameObject.GetComponent <Health>().canAddScore = false; } } } } else { if (fxManager != null) { PhotonNetwork.Instantiate(Particals.name, bulletSpawn.transform.position, bulletSpawn.transform.rotation, 0); Vector3 endPoint; endPoint = bulletSpawn.transform.position + (bulletSpawn.transform.forward * range); crossHair.transform.position = endPoint; fxManager.GetComponent <PhotonView> ().RPC("BulletFx", PhotonTargets.All, bulletSpawn.transform.position, endPoint); } } cooldown = fireRate; } }