Synchronize and change the value and turn
Hello everyone,
I'm doing multiplayer tic tac toe and I can't change the turn and synchronize the value. I would like it when it clicks on a tile, it marks the clicked value to true and changes it to a sprite according to the player, it works only on one player and does not change turns. Does anyone know how I do it?
Thanks in advance.
I'm doing multiplayer tic tac toe and I can't change the turn and synchronize the value. I would like it when it clicks on a tile, it marks the clicked value to true and changes it to a sprite according to the player, it works only on one player and does not change turns. Does anyone know how I do it?
Thanks in advance.
using System.Collections; using System.Collections.Generic; using UnityEngine; using Photon.Pun; using Photon.Realtime; public class PlayerController : MonoBehaviourPun { public Player photonPlayer; // Photon.Realtime.Player class public static PlayerController me; // local player public static PlayerController enemy; // non-local enemy player public bool canPlay; // called when the game begins [PunRPC] void Initialize (Player player) { photonPlayer = player; // if this is our local player, spawn the units if(player.IsLocal) { me = this; } else enemy = this; // set the player text GameUI.instance.SetPlayerText(this); } void Update () { // only the local player can control this player //if(!photonView.IsMine) //return; if (Input.GetMouseButton(0)) { photonView.RPC("MarkTiles", RpcTarget.All); } } [PunRPC] public void MarkTiles() { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit2D hit = Physics2D.Raycast(ray.origin, Vector2.zero, float.PositiveInfinity); if (hit.collider != null && GameManager.instance.curPlayer == this && canPlay) { hit.collider.gameObject.GetComponent<Tile>().clicked = true; hit.collider.enabled = false; hit.collider.gameObject.GetComponent<SpriteRenderer>().sprite = GameManager.instance.oSprite; me.EndTurn(); } else if (hit.collider != null && GameManager.instance.curPlayer == this && canPlay) { hit.collider.gameObject.GetComponent<Tile>().clicked = true; hit.collider.enabled = false; hit.collider.gameObject.GetComponent<SpriteRenderer>().sprite = GameManager.instance.xSprite; enemy.EndTurn(); } } // called when our turn ends public void EndTurn () { // start the next turn GameManager.instance.photonView.RPC("SetNextTurn", RpcTarget.All); canPlay = false; } // called when our turn has begun public void BeginTurn () { canPlay = true; } }
0