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 ziadantar90 · Jul 12, 2014 at 05:34 PM · c#networkingnetworkphoton

Photon network problem

Hey I've been working on a game which two players simultaneously play and a board hanging in the scene shows the player1 score and player2 score.

the game mechanic and coding works fine, whenever player1 scores he gains points and it shows on the board, same goes to player2 but the problem is the points for player1 change in his scene but not in player2's scene.

which means if I'm player 1 I can see my score change but player's 2 score will stay at zero the whole game while in his scene it's changing.

I've been using Photon for the networking in Unity.

The board is a gameobject which has a script that is called by a trigger of each player but I want the result to be the same in both players' scenes.

any help ?!

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

2 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by Firedan1176 · Jul 13, 2014 at 01:15 AM

To expand from taylank's answer, you do need to use RPC. On the object that the scoreboard script is on, place a Photon View component. Now if the scoreboard is already in the game and isn't instantiated when the game runs, you don't have to put anything in the observe blank. Now, within the scoreboard script, you're going to need to send an RPC so that the other player can receive it. This is how it works:

  1. The scoreboard is updated or whatever and you need to send the new scores.

  2. You use the RPC function to basically send a variable over the network to a function on the other person's computer.

  3. Their scoreboard is updated.

In this example, I will be sending the score and the username to all other players (well just 2 in your example; you and the other player). To do this, I will grab the PhotonView on my 'scoreboard' gameobject (or whatever object has the scoreboard script on it), and call an RPC within that PhotonView, and include the username and the score.

 GetComponent<PhotonView>().RPC ("UpdateScores", myUsername, myCurrentSore);

Now what this will do is call the function "UpdateScores" on every player's scoreboard script and feed in the username and the score of that player. Only problem is "UpdateScores" doesn't exist as a function (You're going to add it now).

Now, since both you and the other player need to synchronize, you'll need to make a function (void in C#) that will receive that incoming information. You'll also need to include @RPC (for JavaScript) before you declare the function or [RPC] for C#. My example will be using C#.

 [RPC]
 void UpdateScores(string username, float score) {
 //Keep in mind that it doesn't matter that 'username' and 'score' above are the same as when you send it; they just need to both be the same Type of variable, such as string and float.
 //You now have the username and the score on other clients. Do your 'update' stuff here.



 }

Keep in mind since you're calling all functions on all computers, you are also calling it on your computer. Therefore, your game will also be updated. It doesn't really matter as yours will be updated anyways.

If you need more understanding, you can comment or look at the documentation for Photon Unity Networking (click here). I hope I answered your question.

Comment
Add comment · Share
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
0

Answer by taylank · Jul 13, 2014 at 12:46 AM

You should probably use a RPC function to change the players' scores, so that the change is reflected in each view. I believe there are examples of RPC use in Photon's Marco Polo tutorial:

http://doc.exitgames.com/en/pun/current/tutorials/tutorial-marco-polo

Check out the section titled Shout & Respond.

Comment
Add comment · Share
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

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

Matchmaking multiplayer help 0 Answers

Photon wont sync for the masterclient. 1 Answer

Unity3D Photon movement synchronization 0 Answers

Networking Sync SetActive Not Working 0 Answers

remove spawned object from my networkView when timeScale = 0 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