kadyr

Untitled

Sep 18th, 2021
548
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using Photon.Pun;
  5.  
  6. public class NetworkMove : MonoBehaviour, IPunObservable
  7. {
  8.     [SerializeField]
  9.     private List<Material> skins = new List<Material>();
  10.  
  11.     [SerializeField]
  12.     private Renderer skinRender; // наш текущий скин
  13.  
  14.     private int currentSkin = 0;
  15.     PhotonView _photonView;
  16.  
  17.  
  18.     public bool finish;
  19.  
  20.     void Start()
  21.     {
  22.         _photonView = GetComponent<PhotonView>();
  23.         ChangeSkin(0);
  24.         if (!_photonView.IsMine)
  25.         {
  26.             GetComponent<PlayerLook>().enabled = false;
  27.             GetComponent<GuyMove>().enabled = false;
  28.             GetComponentInChildren<Camera>().gameObject.SetActive(false);
  29.         }
  30.     }
  31.  
  32.     void Update()
  33.     {
  34.         if (_photonView.IsMine)
  35.         {
  36.             if (Input.GetKeyDown(KeyCode.Alpha0))
  37.             {
  38.                 ChangeSkin(0);
  39.             }
  40.             if (Input.GetKeyDown(KeyCode.Alpha1))
  41.             {
  42.                 ChangeSkin(1);
  43.             }
  44.             if (Input.GetKeyDown(KeyCode.Alpha2))
  45.             {
  46.                 ChangeSkin(2);
  47.             }
  48.         }
  49.     }
  50.  
  51.     public void ChangeSkin(int skinNum)
  52.     {
  53.         skinRender.material = skins[skinNum];
  54.         currentSkin = skinNum;
  55.     }
  56.  
  57.     public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
  58.     {
  59.         if (stream.IsWriting)
  60.         {
  61.             stream.SendNext(finish);
  62.             stream.SendNext(currentSkin);
  63.         }
  64.         else
  65.         {
  66.             finish = (bool)stream.ReceiveNext();
  67.             currentSkin = (int)stream.ReceiveNext();
  68.             ChangeSkin(currentSkin);
  69.         }
  70.     }
  71. }
RAW Paste Data