Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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 naltradamus · Jul 09, 2015 at 03:58 PM · photonscorescoreboard

scoreboard for multiplayer game

could someone please help, Ive been scratching at this for more than two weeks and just cant figure out how to properly display an ingame scoreboard for players to view during a game. so far I've been able to spawn the entries on to the board but for some reason when a player scores the opposite player gets the points. I'm so stomped on this.. any help would be much appreciated!

I have a gameObject that works as a grid (leaderboardgrid) and the actual gameobject that gets spawned when each player joins the game (leaderboardEntry).. heresthe scripts for both:

leaderboardgrid:

 public class MULeaderboardsSCORE : Photon.MonoBehaviour {
     
     public GameObject leaderboardEntryPre;
     public Transform leaderboardgrid;
     public string scoreString, usernameString, facebookID = "";
     public List<GameObject> entries = new List<GameObject>();
     public bool GetLB;
     PhotonPlayer tempPlayer;
     GameObject leaderboardEntry;
 
     void Start()
     {
         GetLB = true;
     }
     
     [RPC] void GetLeaderBeard(string newUsername, string newScore, string newFBimage) {
 
         Debug.Log ("Leaderboard Updated");
         leaderboardEntry = (GameObject)Instantiate (leaderboardEntryPre);
         leaderboardEntry.transform.SetParent (leaderboardgrid, false);
         leaderboardEntry.GetComponent<MULeaderboardEntry> ().rankString = (entries.Count + 1).ToString ();
         leaderboardEntry.GetComponent<MULeaderboardEntry> ().usernameString = newUsername;
         leaderboardEntry.GetComponent<MULeaderboardEntry> ().facebookID = newFBimage;
         leaderboardEntry.GetComponent<MULeaderboardEntry> ().scoreString = newScore;
         if (PhotonNetwork.player.customProperties ["username"].ToString () == newUsername) {
             tempID = PhotonNetwork.player.ID;
             leaderboardEntry.GetComponent<PhotonView> ().TransferOwnership (tempID);
             Debug.Log ("Leaderboard Updated " + tempID);
         }
         entries.Add (leaderboardEntry);
     }
 
     [RPC] void UpdateMyScore(int MyScore){
         leaderboardEntry.GetComponent<MULeaderboardEntry> ().scoreInt = MyScore;
         Debug.Log (leaderboardEntry.GetComponent<MULeaderboardEntry> ().usernameString + "'s new score is " + MyScore);
     }
 
         void Update(){
 
             if( GetLB == true){
                  
                 
                 if(PhotonNetwork.player.customProperties ["username"].ToString () == GameInformation.UserName){
                     tempPlayer = PhotonNetwork.player;
                     if (tempPlayer.customProperties ["score"].ToString () != null) {
                     usernameString = tempPlayer.customProperties ["username"].ToString ();
                     scoreString = tempPlayer.customProperties ["score"].ToString ();
                     facebookID = tempPlayer.customProperties ["FBImage"].ToString ();
                     GetComponent<PhotonView>().RPC ("GetLeaderBeard", PhotonTargets.AllBuffered, usernameString, scoreString, facebookID);
                     GetLB = false;
                     }
                 }
             }
 
         if (GetLB == false) {
 
             if (scoreString != tempPlayer.customProperties ["score"].ToString ()) {
                 scoreString = tempPlayer.customProperties ["score"].ToString ();
                 int NewScoreInt = int.Parse (scoreString);
                     GetComponent<PhotonView> ().RPC ("UpdateMyScore", PhotonTargets.AllBuffered, NewScoreInt);
             }
         }
 }


and the leaderboardEntry:

 public class MULeaderboardEntry : Photon.MonoBehaviour {
 
 
     public string rankString, usernameString, scoreString, facebookID = ""; 
     public Text rank, username, xp;
     private Texture2D tempPic;
     public RawImage FBImage;
     public int scoreInt;
     public bool tempHS = false;
 
     // Use this for initialization
     void Start () {
 
         rank.text = rankString;
         username.text = usernameString;
         if (facebookID != null) {
             StartCoroutine (getFBPicture ());
             Debug.Log ("Found FB ID");
         } else {
             facebookID = "TeamHyptown";
             StartCoroutine (getFBPicture ());
             Debug.Log ("Set FB ID");
         }
         if (scoreString != null) {
             scoreInt = int.Parse (scoreString);
             xp.text = scoreInt.ToString ();
             Debug.Log ("Score Updated Per Entry");
             tempHS = true;
         }
         if (photonView.isMine == true) {
             gameObject.tag = "Leaderboard";
         }
     }
 
     void Update(){
         if (tempHS == true) {
             if (xp.text != scoreInt.ToString()) {
                 xp.text = scoreInt.ToString();
                 scoreString = scoreInt.ToString();
             }
         }
     }
 
     public IEnumerator getFBPicture (){
         var www = new WWW ("http://graph.facebook.com/" + facebookID + "/picture?width=210&height=210");
         
         yield return www;
         yield return new WaitForEndOfFrame();
         Texture2D tempPic = new Texture2D (25, 25, TextureFormat.RGB24, false);
         
         www.LoadImageIntoTexture (tempPic);
         tempPic.ReadPixels(new Rect(0, 0, 25, 25), 0, 0);
         tempPic.Apply();
         FBImage.texture = tempPic;
     }
 }
Comment
Add comment · Show 1
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
avatar image fuego_see_money · Jul 09, 2015 at 05:51 PM 0
Share

Question - is this saved? Do you reset the scores of each player after the game ends, or is it like a "lifetime" leaderboard? If its not the ladder, you should use PhotonNetwork.player for each player's scores. Its a very handy attribute of PUN. Let me know if this is the situation and i can give you an example.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

How to make an online scoreboard -1 Answers

Photon - Distinguishing player types for spawns 0 Answers

Getting an "Unknown Resolve Error" with Photon.MonoBehaviour 1 Answer

Multiplayer ScoreBoard not Updating Correctly 0 Answers

how to creat and scoring and high score system for an endless runner,how do I display my score on a game over scene and also create and high score system for the same ? 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