Advertisement
Guest User

Photon

a guest
Sep 19th, 2016
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.52 KB | None | 0 0
  1. //////////////////////////NETWORK SCRIPT////////////////////////////
  2. using UnityEngine;
  3.  
  4. public class Network : Photon.PunBehaviour
  5. {
  6.     private PhotonView myPhotonView;
  7.  
  8.     // Use this for initialization
  9.     void Start()
  10.     {
  11.         PhotonNetwork.ConnectUsingSettings("0.1");
  12.     }
  13.  
  14.     public override void OnJoinedLobby()
  15.     {
  16.         Debug.Log("JoinRandom");
  17.         PhotonNetwork.JoinRandomRoom();
  18.     }
  19.  
  20.     public override void OnConnectedToMaster()
  21.     {
  22.         PhotonNetwork.JoinRandomRoom();
  23.     }
  24.  
  25.     public void OnPhotonRandomJoinFailed()
  26.     {
  27.         PhotonNetwork.CreateRoom(null);
  28.     }
  29.  
  30.     public override void OnJoinedRoom()
  31.     {
  32.         GameObject player = PhotonNetwork.Instantiate("Player", Vector3.zero, Quaternion.identity, 0);
  33.         myPhotonView = player.GetComponent<PhotonView>();
  34.     }
  35. }
  36.  
  37. //////////////////////////PLAYER SCRIPT////////////////////////////
  38. using UnityEngine;
  39.  
  40. public class Player : Photon.MonoBehaviour
  41. {
  42.  
  43.     private Vector3 targetPos;
  44.  
  45.     // Use this for initialization
  46.     void Start ()
  47.     {
  48.         if (!photonView.isMine)
  49.             this.enabled = false;
  50.  
  51.         targetPos = transform.position;
  52.     }
  53.    
  54.     // Update is called once per frame
  55.     void Update ()
  56.     {
  57.         if(Input.GetMouseButtonDown(0))
  58.         {
  59.             targetPos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
  60.             targetPos.z = 0;
  61.         }
  62.  
  63.         transform.position = Vector3.MoveTowards(transform.position, targetPos, 3.5F * Time.deltaTime);
  64.     }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement