Advertisement
Dieton

SceneScript

May 28th, 2023
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.40 KB | Gaming | 0 0
  1. using Mirror;
  2. using UnityEngine;
  3. using UnityEngine.UI;
  4. using TMPro;
  5. using UnityEngine.SceneManagement;
  6.  
  7. namespace QuickStart
  8. {
  9.     public class SceneScript : NetworkBehaviour
  10.     {
  11.         public TMP_Text canvasStatusText;
  12.         public PlayerScript playerScript;
  13.         public SceneReference sceneReference;
  14.  
  15.         [SyncVar(hook = nameof(OnStatusTextChanged))]
  16.         public string statusText;
  17.  
  18.         public TMP_Text canvasAmmoText;
  19.  
  20.         void OnStatusTextChanged(string _Old, string _New)
  21.         {
  22.             //called from sync var hook, to update info on screen for all players
  23.             canvasStatusText.text = statusText;
  24.         }
  25.  
  26.         public void ButtonSendMessage()
  27.         {
  28.             if (playerScript != null)
  29.                 playerScript.CmdSendPlayerMessage();
  30.         }
  31.  
  32.         public void ButtonChangeScene()
  33.         {
  34.             if (isServer)
  35.             {
  36.                 Scene scene = SceneManager.GetActiveScene();
  37.                 if (scene.name == "MyScene")
  38.                     NetworkManager.singleton.ServerChangeScene("MyOtherScene");
  39.                 else
  40.                     NetworkManager.singleton.ServerChangeScene("MyScene");
  41.             }
  42.             else
  43.                 Debug.Log("You are not Host.");
  44.         }
  45.  
  46.         public void UIAmmo(int _value)
  47.         {
  48.             canvasAmmoText.text = "Ammo: " + _value;
  49.         }
  50.     }
  51. }
Tags: Unity mirror
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement