- Home /
Multiplayer gameboard: Each player can see the mouse pointer moving over the network
Hi!
I'm working in a multiplayer gameboard, and I'm trying to do that each player can see the mouse pointer moving over the network, represented by a typical hand image.
I only get that each hand image follows mouse pointer of each player, but anyone can see the mouse pointer moving over the network.
I'm trying with an empty Gameobject which have a canvas with two hand images (black and white) being part of the player prefab, or being part of the hierarchy, or instantiated by the player prefab and attaching one script like this:
void Update() {
gameManager=FindObjectOfType<GameManager>();
if(gameManager.count>=2)
{
if(photonView.IsMine)
{
WhiteCursorImage.enabled=false;
Vector3 mousePos = (Input.mousePosition -
GameObject.FindGameObjectWithTag("CanvasPointers").GetComponent<RectTransform>
().localPosition);
BlackCursorImage.GetComponent<RectTransform>().localPosition = new Vector3(mousePos.x +
15, mousePos.y - 15, mousePos.z);
}
else
{
BlackCursorImage.enabled=false;
Vector3 mousePos = (Input.mousePosition -
GameObject.FindGameObjectWithTag("CanvasPointers").GetComponent<RectTransform>
().localPosition);
WhiteCursorImage.GetComponent<RectTransform>().localPosition = new Vector3(mousePos.x +
15, mousePos.y - 15, mousePos.z);
}
}
}
Sending position over the network with IPun Observable in the same script with something like this:
#region IPunObservable implementation
public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
{
if (stream.IsWriting)
{
// We own this player: send the others our data
stream.SendNext(BlackCursorImage.transform.position);
}
else
{
// Network player, receive data
this.BlackCursorImage.transform.position= (Vector3)stream.ReceiveNext();
}
if (stream.IsWriting)
{
// We own this player: send the others our data
stream.SendNext(WhiteCursorImage.transform.position);
}
else
{
// Network player, receive data
this.WhiteCursorImage.transform.position= (Vector3)stream.ReceiveNext();
}
}
#endregion
I dont' know if its' better way to do this. Anybody could help me? Thanks!
Your answer
![](https://koobas.hobune.stream/wayback/20220613033835im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Screen.lockCursor leaves mouse where it was 2 Answers
Multiplayer MouseLook controlling other cameras. 0 Answers
How to write a multiplayer game that uses a dedicated server? 0 Answers
Multiplayer Realizations 0 Answers
Unet Matchmaker stopped finding matches suddenly in different LAN network. 0 Answers