Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by romanhutsulyak · Jun 07, 2020 at 12:25 PM · playerphotonissuesscoreboard

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);
                     
                 }
                
             }
     
         }
     
     
     }
    
    
    
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

163 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges