why player that win not stop run but other stop.

++++++++++++++++++++++++++++ this game control script++++++++++++++++++++++++++++++++++++++
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using Photon.Pun;
using Photon.Realtime;
using NameSpacePlayerControl;

namespace NameSpaceGameControl
{
    public class GameControl : MonoBehaviourPunCallbacks
    {
        public Text DeclareNumber;
        public Text txtWinner, ListAllNumber;
        public string strRandomNumber;
        private string[] BallNumber = { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15" };
        private bool xx;



        // Start is called before the first frame update
        void Start()
        {
            xx = false;
            txtWinner.text = "";
            ListAllNumber.text = "";
            StartCoroutine(StartGame());
        }

        IEnumerator StartGame()
        {
            do
            {
                var ChkPlayerStatus = FindObjectOfType<PlayerControl>(); 
                xx = ChkPlayerStatus.PlayerStatus; //Get Player staus from Player Control
                if (xx)                 //if Player Status Win(true)
                {
                    Debug.Log("win = " + xx);
                    txtWinner.text = "Has Player Win";
                    break;
                }
                else
                {
                    if (PhotonNetwork.IsMasterClient)
                    {
                        strRandomNumber = BallNumber[Random.Range(0, BallNumber.Length)]; //Master Client Random Number
                        photonView.RPC("RandomNumber", RpcTarget.All, strRandomNumber); //Send Random Number to all player
                    }
                }
                Debug.Log("now = " + xx);
                yield return new WaitForSeconds(2);
            } while (!xx); //if player status not win(true)
            ListAllNumber.text = ListAllNumber.text + txtWinner.text; //For check that out of loop
            Debug.Log("GameEnd");
        }

        [PunRPC]
        void RandomNumber(string xxx)
        {
            var listNumber = new List<string>(BallNumber);
            DeclareNumber.text = xxx;
            listNumber.Remove(DeclareNumber.text);
            BallNumber = listNumber.ToArray();
            txtWinner.text = txtWinner.text + DeclareNumber.text + " ";
            ListAllNumber.text = ListAllNumber.text + DeclareNumber.text + " ";
        }
    }
}

+++++++++++++++++++++++++++++++++++this player control scripts+++++++++++++++++++++++++++++++
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using Photon.Pun;
using Photon.Realtime;
using NameSpaceGameControl;

namespace NameSpacePlayerControl
{
    public class PlayerControl : MonoBehaviourPunCallbacks
    {

        [SerializeField] public GameObject[] NumberOnCard = new GameObject[4]; //Number for player
        [SerializeField] public GameObject[] Mark = new GameObject[4]; //Marker when number from gamecontrol
        [SerializeField] public bool[] IsMark = new bool[4]; //for check that Number is marked
        private string[] NumberForPlayer = { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15" };
        public bool PlayerStatus;

        private void Awake()
        {
            PlayerStatus = false;
            var listNumberForPlayer = new List<string>(NumberForPlayer); 
            for (int i = 0; i < 4; i++) //Random 4 number for player
            {
                NumberOnCard[i].GetComponent<Text>().text = NumberForPlayer[Random.Range(0, NumberForPlayer.Length)];
                Mark[i].name = NumberOnCard[i].GetComponent<Text>().text;
                IsMark[i] = false;
                listNumberForPlayer.Remove(NumberOnCard[i].GetComponent<Text>().text);
                NumberForPlayer = listNumberForPlayer.ToArray();
            }
        }

        // Update is called once per frame
        void Update()
        {
            if (!photonView.IsMine)
            {
                return;
            }
            if (PlayerStatus)
            {
                return;
            }
            var RecieveNumber = FindObjectOfType<GameControl>(); 
            string xx = RecieveNumber.DeclareNumber.text;  //Get Number from Game Control
            Debug.Log("DeclareNumber = " + xx);
            MarkNumber(xx); // Show Marker on number
            CheckMarkOnCard(xx); //Set Number of player is marked
            if (IsMark[0] && IsMark[3]) //if Number position 0 and 3 is Marked this player win
            {
                PlayerStatus = true;
                photonView.RPC("HasPlayerWin", RpcTarget.All, PlayerStatus); //Send to all player "I am win"
            }
            Debug.Log("PlayerStatus = " + PlayerStatus);
        }

        public void MarkNumber(string BingoBall)
        {
            foreach (Image gameObj in GameObject.FindObjectsOfType<Image>())
            {
                if (gameObj.name == BingoBall)
                {
                    gameObj.GetComponent<Image>().enabled = true;
                }
            }
        }

        public void CheckMarkOnCard(string BallNumber)
        {
            for (int i = 0; i < 4; i++)
            {
                if (NumberOnCard[i].GetComponent<Text>().text == BallNumber)
                {
                    IsMark[i] = true;
                }
            }
        }

        [PunRPC]
        public void HasPlayerWin(bool xxx)
        {
            xxx = true;
            PlayerStatus = xxx;
        }
    }
}

Comments

  • Concept Process
    1.Random one number show on txtWinner and ListAllNumber;
    2.All player use same number. I use RPC for this.
    3.Send number to player. I use namespace for this
    4.Player check for win. If random number equal number in position 1 and 4 will win
    5. Check for win then send player status to all player . I am win. Program will stop for all player.
    6. [img]file:///C:/Users/ASUS_082/Documents/unity%20bingo%20game/%E0%B8%96%E0%B8%B2%E0%B8%A1%E0%B8%9B%E0%B8%B1%E0%B8%8D%E0%B8%AB%E0%B8%B2/%E0%B8%AA%E0%B9%84%E0%B8%A5%E0%B8%94%E0%B9%8C3.JPG[/img]

  • How can I attach picture
Sign In or Register to comment.