Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Countdown photon

Discussion in 'Scripting' started by IbrahimAlkaber, Mar 25, 2020.

  1. IbrahimAlkaber

    IbrahimAlkaber

    Joined:
    Dec 9, 2019
    Posts:
    53
    I did this script and it works fine but there is a problem, when I enter room it works fine and countdown works, but when someone else enters the room it counts down again, I want when a player enters, the camera is placed on the player who was already in the room.
    sorry for my english


    Code (CSharp):
    1.    private Text TimeUIText;
    2.     private float timeToStartRace = 5.0f;
    3.     private void Awake()
    4.     {
    5.         TimeUIText = DeathMatchGameController.instance.TimeUIText;
    6.     }
    7.     // Start is called before the first frame update
    8.     void Start()
    9.     {
    10.     }
    11.     // Update is called once per frame
    12.     void Update()
    13.     {
    14.         if (PhotonNetwork.IsMasterClient)
    15.         {
    16.             if (timeToStartRace >= 0.0f)
    17.             {
    18.                 timeToStartRace -= Time.deltaTime;
    19.                 photonView.RPC("SetTime", RpcTarget.AllBuffered, timeToStartRace);
    20.             }
    21.             else if (timeToStartRace < 0.0f)
    22.             {
    23.                 photonView.RPC("StartTheRace", RpcTarget.AllBuffered);
    24.             }
    25.         }
    26.     }
    27.     [PunRPC]
    28.     public void SetTime(float time)
    29.     {
    30.         if (time > 0.0f)
    31.         {
    32.             TimeUIText.text = time.ToString("F0");
    33.         }
    34.         else
    35.         {
    36.             //The countdown is over
    37.             TimeUIText.text = "";
    38.         }
    39.     }
    40.     [PunRPC]
    41.     public void StartTheRace()
    42.     {
    43.         GetComponent<CarUserControl>().enabled = true;
    44.         this.enabled = false;
    45.     }
     
  2. IbrahimAlkaber

    IbrahimAlkaber

    Joined:
    Dec 9, 2019
    Posts:
    53
    Any help please