Code Review? PUN Scoreboard
Options
Hi All,
I've created a very, very, very basic scoreboard that'll be overhauled closer to my games release. At the moment, all I need is to get information from it (to test more things such as giving scores).
There is very little documentation for Photon with Unity 5 and the new UI, so I've tried working this one out for myself.
Could any of you give me a code review please? Tell me best practice? I know my method probably isn't great. Although it does work.
I've created a very, very, very basic scoreboard that'll be overhauled closer to my games release. At the moment, all I need is to get information from it (to test more things such as giving scores).
There is very little documentation for Photon with Unity 5 and the new UI, so I've tried working this one out for myself.
Could any of you give me a code review please? Tell me best practice? I know my method probably isn't great. Although it does work.
using UnityEngine; using System.Collections; using UnityEngine.UI; public class ScoreManager : Photon.PunBehaviour { public GameObject panel; Text username; public Font myFont; bool scoreboardOpen = false; // Use this for initialization void Start() { } // Update is called once per frame void Update() { if(Input.GetKeyDown(KeyCode.Tab)) { panel.SetActive(true); foreach (PhotonPlayer pl in PhotonNetwork.playerList) { GameObject emptyGameObject = new GameObject(pl.ToString()); emptyGameObject.transform.position = new Vector3(panel.transform.position.x, panel.transform.position.y, panel.transform.position.x); emptyGameObject.transform.SetParent(panel.transform); username = emptyGameObject.AddComponent<Text>(); username.text = pl.ToString() + " " + pl.GetScore(); username.font = Font.CreateDynamicFontFromOSFont("Arial", 12); username.color = Color.black; } } if (Input.GetKeyUp(KeyCode.Tab)) { foreach(Transform child in panel.transform) { Destroy(child.gameObject); } panel.SetActive(false); } } }Edit: "bool scoreboardOpen = false;" will be removed. I realised I only wanted to show the scoreboard when the tab key is being pressed.
0