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 missypooh · Mar 23, 2012 at 04:04 PM · networkingrpcnetworkview

How to update score (M2H networking)

Hello,

I am using M2H networking tutorial example4(FPS games) for my games. So i only used the gameSetup, FPSChat and ScoreBoard for my games. So now what i would like to ask is how to update my score table? It is quite hard for me to update the table as i feel that the score script somehow rely on gamesetup.correct me if i am wrong.

http://www.m2h.nl/unity/

So now i will have my own gamecontrol. So how can i go about updating the score at the score script??

 #pragma strict
 #pragma implicit
 #pragma downcast
 
 var skin                                         : GUISkin;
 
 //static var newRecordMessage                 : String = "";
 
 private var displayingHighscore         : boolean = false;
 private var highscoreText                 : GUIText;
 
 private var playerName                     : String = "";
 private var score                            : int = 0;
 
 private var scoreText                         : String = "Loading scores";
 
 private var hidestats                         : boolean = true;
 private var scoreBoardHeight             : int = 150;
 private var gameSetupScript             : GameSetup;
 
 function Awake()
 {
     gameSetupScript = GetComponent(GameSetup);
     
     //highscoreText = GetComponent(GUIText);
     //highscoreText.enabled=false;
     playerName            = PlayerPrefs.GetString("playerName");
 }
 
 function OnGUI () 
 {
     GUI.skin = skin;
 
     //scoreText = "Scoreboard:\n";
     scoreText = "Players in the game:\n";
     
     for(var entry : FPSPlayerNode in  gameSetupScript.playerList)
     {
         //scoreText += entry.playerName+" \t"+" score:  " + openableDoor1.score1 + "\n";    
         scoreText += entry.playerName+" \n";    
         //print(scoreText);
     }
 
     GUILayout.BeginArea (Rect ((Screen.width-1020),10,175,scoreBoardHeight));
     GUILayout.Box(scoreText);
     GUILayout.EndArea ();
 }
 
 
 function LocalPlayerHasKilled()
 {
     var kills             : int =0;
     var score         : int =0;
     
     for (var playerInstance : FPSPlayerNode in gameSetupScript.playerList) 
     {
         if (Network.player == playerInstance.networkPlayer) 
         {
             //kills     = playerInstance.kills;
             score = playerInstance.score;
             
             break;
         }
     }
     
     kills++;
     
     //Overwrite the data of other players with the new correct score
     networkView.RPC("UpdateScore",RPCMode.All, Network.player, score); 
 }
 
 function LocalPlayerDied()
 {
     var kills         : int = 0;
     var deaths : int = 0;
     var score    : int = 0;
     
     for (var playerInstance : FPSPlayerNode in gameSetupScript.playerList) 
     {
         if (Network.player == playerInstance.networkPlayer) 
         {
             //kills = playerInstance.kills;
             score = playerInstance.score;
             //print("score at SB:" + playerInstance.score);
             //print("i am inside localPlayerDied");
             break;
         }
     }    
     //deaths++;
     
     //Overwrite with new correct score
     //RPCMode.All -> RPC call on everyone who is connected to the server but did not tell him to buffer the call for clients which connect later
     networkView.RPC("UpdateScore",RPCMode.All, Network.player,score); 
 }
 
 @RPC
 function UpdateScore(player : NetworkPlayer,score : int)
 {
     print("I am inside scoreBoard UpdateScores RPC");
     Debug.Log((Network.player==player)+"= local "+ score + "score");
     
     var found : boolean = false;
     
     for (var playerInstance : FPSPlayerNode in gameSetupScript.playerList) 
     {
         if (player == playerInstance.networkPlayer) 
         {
             //playerInstance.kills=kills;
             playerInstance.score = score;
             found=true;
             break;            
         }
     }    
     
     if(!found)
     {
         Debug.LogError("Could not find network player "+player+" in the gamesetup playerlist!");
     }
     
     scoreBoardHeight = gameSetupScript.playerList.Count*15+40;        
 }

P.S This is the script that i will use to store my score.

Comment
Add comment · Show 3
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 GameFreak · Mar 23, 2012 at 07:50 PM 0
Share

Do you want to update the score online or just want a simple leaderboard?

A simple leaderboard I can explain you. Online sorry, no experience (Except using gamecenter plugins)

avatar image missypooh · Mar 23, 2012 at 11:39 PM 0
Share

What you mean by update online?? No, i want a simple leaderboard that will update all players in the games plus to store the value to mysql..

avatar image GameFreak · Mar 24, 2012 at 09:21 AM 0
Share

See if you just want an offline leaderboard - Of that player only (the player who is using your game) simply use PlayerPrefs http://unity3d.com/support/documentation/ScriptReference/PlayerPrefs.html

If you want a world leaderboard use one of the GameCenter plugins :)

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Get NetworkPlayer from ViewID 1 Answer

Networking: RPC To Specific Player? 1 Answer

networkView not called on Child objects? 0 Answers

NetworkView conflicts between Levels 1 Answer

Couldn't Invoke RPC Function ! 1 Answer


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