Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class HostScript : Photon.MonoBehaviour
- {
- public float speed = 10f;
- volatile bool isMyTurn = true;
- // Use this for initialization
- void Start () {
- isMyTurn = true;
- }
- // Update is called once per frame
- void Update()
- {
- if (photonView.isMine && isMyTurn)
- {
- InputMovement();
- }
- }
- void InputMovement()
- {
- if (Input.GetKey(KeyCode.W))
- rigidbody.MovePosition(rigidbody.position + Vector3.forward * speed * Time.deltaTime);
- if (Input.GetKey(KeyCode.S))
- rigidbody.MovePosition(rigidbody.position - Vector3.forward * speed * Time.deltaTime);
- if (Input.GetKey(KeyCode.D))
- rigidbody.MovePosition(rigidbody.position + Vector3.right * speed * Time.deltaTime);
- if (Input.GetKey(KeyCode.A))
- rigidbody.MovePosition(rigidbody.position - Vector3.right * speed * Time.deltaTime);
- if (Input.GetKey(KeyCode.Space))
- {
- photonView.RPC("nextTurn", PhotonTargets.All, PhotonNetwork.player.ID);
- }
- }
- [RPC] void nextTurn(int id)
- {
- // I pressed the button
- if (id == PhotonNetwork.player.ID)
- {
- isMyTurn = false;
- }
- // Another player called it
- else
- {
- isMyTurn = true;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement