Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 dcox45 · May 01, 2019 at 11:35 PM · multiplayerphotonscopescoring

What is a general strategy for making a multiplayer scoring system using in-game sprites instead of UI elements?

I am making a basketball shooting game, and in the Scene there is a Scoreboard GameObject that shows 1-4 players' scores in real-time as they score two-pointers. The scores for each player will consist of 3 numbers (so, starting by default at 000), and increments by 2 for every time OnGoal event is triggered, by changing the first 0 sprite into a 2 sprite, and so on.

So, in contrast to many multiplayer scoring scripts, mine will not be working with Text UI objects representing score numbers, but with in-game sprites / GameObjects that are Instantiated from number prefabs.

Each of the 3 sprites is parented to a field transform (attached to an empty GameObject) which sits on the Scoreboard. This is used to determine the position of a digit, as well as which digit is to be incremented to increase the score by 2. Here is my current ScoreManager script:

 public class ScoreManager : MonoBehaviour
     {
         [SerializeField]
         GameObject[] loadedNumbers;         // load the number sprite prefabs
         List<GameObject> numbers;           // instantiate the loaded numbers 
 
         public Transform[] field;           // 3 fields for a max score of 999
         GameObject[] activeObj;             // the objects being currently used to represent a score 
         int scores = 0;                     // the current score 
         public static ScoreManager data;       
 
         // Score Colors 
         [SerializeField] private Material[] scoreColorMats;
 
 
         // Start is called before the first frame update
         void Start()
         {
             data = this;
             activeObj = new GameObject[field.Length];
 
             numbers = new List<GameObject>();
 
 
             for (int i = 0; i < loadedNumbers.Length; i++)
             {
                 numbers.Add(Instantiate(loadedNumbers[i], new Vector3(100,100,100), Quaternion.identity, transform));
             }
 
             for (int i = 0; i < numbers.Count; i++)                 // this is just used to color the sprites according to the different players 
             {
                 numbers[i].GetComponent<SpriteRenderer>().material = scoreColorMats[0];
             }
 
             SetValue(scores);
 
 
         }
 
         public void Inc()   //increments the player score by 2
         {
             Clear();
             if (scores < 999)
             {
                 scores += 2;
             }
             SetValue(scores);
         }
 
         public void Dec()  //decrements the player score 
         {
             if (scores > 0)
             {
                 scores--;
             }
             SetValue(scores);
         }
 
         void Clear()
         {
             for (int i = 0; i < field.Length; i++)
             {
                 Destroy(activeObj[i]);
             }
         }
 
         void SetValue(int scores)
         {
             int Convert = 1;
             for (int i = 0; i < field.Length; i++)
             {
                 int scoreConvert = (scores / Convert) % 10;
                 Print(i, scoreConvert, i);
                 Convert *= 10;
 
             }
         }
 
         void Print(int activeObj, int scores, int field)
         {
             this.activeObj[activeObj] = Instantiate(this.numbers[scores], this.field[field].position, this.field[field].rotation);
             this.activeObj[activeObj].name = this.field[field].name;
             this.activeObj[activeObj].transform.parent = this.field[field];
         }
 
         // Update is called once per frame
         void Update()
         {
 
         }
     }



And here is where the Inc method is actually called from a separate script called ShootManager. We instantiate the class ScoreManager script as a variable sm:

 void Goal(float distance, float height, bool floored, bool clear, bool special, PhotonView view)
         {
             Debug.Log("SCORED");
 
             sm.Inc();   // increment score
 
             showTwoPoints(view);
 
         }



I am using Photon to send this player score data across a network, so I will also need to use RPCPun and RaiseEvent calls. But just knowing how to handle all these sprites will be a good start if you are not familiar with Photon.


The reason I ask for a "general" strategy is that I know that there are potentially multiple ways to go about this. Scoping and access are also not my strong suit, and so I would like to get a picture of how my ScoreManger script might handle the changing of sprite numbers for multiple players across a Photon network. Thanks in advance for any guidance!

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

180 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 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

How to get all created rooms and join any one of them in PHOTON 2 Answers

[PUN2] Problem at pushing the other players 1 Answer

The player who leaves second is not being able to create or join room - Unity Photon Network 2 Answers

How to make that when someone presses a button the function of the button happens to everyone. Photon Pun 1 Answer

Is that any way to pass list of array through photon? 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