- Home /
Score System Problem usying Photon
Guys so i'm having some issues and i'm trying to do a scoreboard and i'm usying an script that comes with photonNetwork that is called PunPlayerScores and the issue is everytime i hit a player it counts the number of the times i hited him instead i want it to count 1 scorepoint when he dies so the point goes to the player that killed him i'm leaving my health and player shoot scripts , sorry guys i'm noob and i need your help
Blockquote
PlayerShoot script
using System.Collections; using UnityEngine;
public class PlayerShoot : MonoBehaviour {
float cooldown = 0; FXManager fxManager; WeaponData weaponData; void Start() { } void Update() { cooldown -= Time.deltaTime; if (Input.GetButton("Fire1")) { Fire(); } } //ESTA FUNÇAO CORRE A FUNCÇAO FIRE PELA NETWORK E FAZ MOSTRAR OS OBJETOS E AS ARMAS PELA NETWORK TAMBEM FAZ O PLAYER RECEBER DAMAGE PELA NETWORK void Fire() { fxManager = GameObject.FindObjectOfType<FXManager>(); if (weaponData == null) { weaponData = gameObject.GetComponentInChildren<WeaponData>(); return; } if (cooldown > 0) { return; } Ray ray = new Ray(Camera.main.transform.position, Camera.main.transform.forward); Transform hitTransform; Vector3 hitPoint; hitTransform = FindClosestHitObject(ray, out hitPoint); if (hitTransform != null) { Health h = hitTransform.transform.GetComponent<Health>(); while (h == null && hitTransform.parent) { hitTransform = hitTransform.parent; h = hitTransform.transform.GetComponent<Health>(); } if (h != null) { PhotonView pv = h.GetComponent<PhotonView>(); if (pv == null) { Debug.LogError("Freak out"); } else { TeamMember tm = hitTransform.GetComponent<TeamMember>(); TeamMember myTm = this.GetComponent<TeamMember>(); if (tm == null || tm.teamID == 0 || myTm == null || myTm.teamID == 0 || tm.teamID != myTm.teamID) { h.GetComponent<PhotonView>().RPC("TakeDamage", PhotonTargets.AllBuffered, weaponData.damage); PhotonNetwork.player.AddScore(1); } } } if (fxManager != null) { DoGunFX(hitPoint); } } else { if (fxManager != null) { hitPoint = Camera.main.transform.position + (Camera.main.transform.forward * 100f); DoGunFX(hitPoint); } } cooldown = weaponData.fireRate; } void DoGunFX(Vector3 hitPoint) { fxManager.GetComponent<PhotonView>().RPC("SniperBulletFX", PhotonTargets.All, weaponData.transform.position, hitPoint); } Transform FindClosestHitObject(Ray ray, out Vector3 hitPoint) { RaycastHit[] hits = Physics.RaycastAll(ray); Transform closestHit = null; float distance = 0; hitPoint = Vector3.zero; foreach (RaycastHit hit in hits) { if (hit.transform != this.transform && (closestHit == null || hit.distance < distance)) { closestHit = hit.transform; distance = hit.distance; hitPoint = hit.point; } } return closestHit; } }
Blockquote
Health Script
using System.Collections; using UnityEngine; using UnityEngine.UI;
public class Health : MonoBehaviour { public float hitPoints = 100f; float currentHitPoints;
public Text healthText; public GameObject DeathPrefab; PhotonView photonView; // Start is called before the first frame update void Start() { currentHitPoints = hitPoints; photonView = GetComponent<PhotonView>(); healthText = GameObject.Find("Canvas").GetComponentInChildren<Text>(); } [PunRPC] void Update() { if (photonView.isMine) { healthText.text = "Vida: " + currentHitPoints; } } [PunRPC] public void TakeDamage(float amt) { currentHitPoints -= amt; if (currentHitPoints <= 0) { Die(); } } [PunRPC] void Death() { if (DeathPrefab != null) { GameObject DeadFX = PhotonView.Instantiate(DeathPrefab, transform.position, transform.rotation); } } void Die() { if (GetComponent<PhotonView>().instantiationId == 0) { Destroy(gameObject); } else { if (GetComponent<PhotonView>().isMine) if (gameObject.tag == "Player") { NetworkManager nm = GameObject.FindObjectOfType<NetworkManager>(); nm.standbyCamera.SetActive(true); nm.respawnTimer = 5f; } { Death(); PhotonNetwork.Destroy(gameObject); } } } }
Your answer
Follow this Question
Related Questions
Bullet wont collide for the other player (PHOTON+UNITY) 1 Answer
Player names all displayed as local player photon 2 Answers
Unity Photon game scoreboard (player properties) any clear tutorials? 2 Answers
How to get LocalPlayer position in Photon Bootcamp Demo? 1 Answer
Rotate the arms of the player usying ik 0 Answers