Advertisement
Guest User

Untitled

a guest
Jan 20th, 2015
479
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.22 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class HostScript : Photon.MonoBehaviour
  5. {
  6.     public float speed = 10f;
  7.     volatile bool isMyTurn = true;
  8.  
  9.     // Use this for initialization
  10.     void Start () {
  11.         isMyTurn = true;
  12.     }
  13.    
  14.     // Update is called once per frame
  15.     void Update()
  16.     {
  17.         if (photonView.isMine && isMyTurn)
  18.         {
  19.             InputMovement();
  20.         }
  21.     }
  22.    
  23.     void InputMovement()
  24.     {
  25.         if (Input.GetKey(KeyCode.W))
  26.             rigidbody.MovePosition(rigidbody.position + Vector3.forward * speed * Time.deltaTime);
  27.        
  28.         if (Input.GetKey(KeyCode.S))
  29.             rigidbody.MovePosition(rigidbody.position - Vector3.forward * speed * Time.deltaTime);
  30.        
  31.         if (Input.GetKey(KeyCode.D))
  32.             rigidbody.MovePosition(rigidbody.position + Vector3.right * speed * Time.deltaTime);
  33.        
  34.         if (Input.GetKey(KeyCode.A))
  35.             rigidbody.MovePosition(rigidbody.position - Vector3.right * speed * Time.deltaTime);
  36.        
  37.         if (Input.GetKey(KeyCode.Space))
  38.         {
  39.             photonView.RPC("nextTurn", PhotonTargets.All, PhotonNetwork.player.ID);
  40.         }
  41.     }
  42.  
  43.     [RPC] void nextTurn(int id)
  44.     {
  45.         // I pressed the button
  46.         if (id == PhotonNetwork.player.ID)
  47.         {
  48.             isMyTurn = false;
  49.         }
  50.  
  51.         // Another player called it
  52.         else
  53.         {
  54.             isMyTurn = true;
  55.         }
  56.     }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement