I think there is problem between Photon and mouse position. Because when I try to change position of object with keyboard it works successfully but when I try to change position with mouse it is not changing over the network. How can I change object position with mouse position over the network?
public class SpehreControl : MonoBehaviour
{
PhotonView PV;
GameObject sphere1;
GameObject bt;
// Start is called before the first frame update
void Start()
{
PV = GetComponent<PhotonView>();
sphere1 = GameObject.Find("Sphere 1");
bt = GameObject.Find("BT_1");
}
// Update is called once per frame
void Update()
{
if (Input.GetMouseButton(0) && PV.IsMine)
{
PV.RPC("RPC_MoveOnline", RpcTarget.AllBuffered);
}
}
[PunRPC]
void RPC_MoveOnline()
{
transform.position = new Vector3(Camera.main.ScreenToWorldPoint(Input.mousePosition).x,
Camera.main.ScreenToWorldPoint(Input.mousePosition).y, 0);
}
}
I think the problem in RPC function. When you call it, every user receives only a call event with no params. It means, every user work with his own Input.mousePosition but not from the sender.
You can use params to fix this:
...
PV.RPC("RPC_MoveOnline", RpcTarget.AllBuffered, Camera.main.ScreenToWorldPoint(Input.mousePosition));
...
[PunRPC]
void RPC_MoveOnline(Vector3 worldPosition)
{
transform.position = new Vector3(worldPosition.x, worldPosition.y, 0);
}
But it's really not a very good way...
As I see, you need to synchronize the position of some objects for all users. It's much easier to deal with PhotonView component (what your GO already has). Just drag and drop your GO Transform component to the PhotonView Observed Components field in unity inpector.
Using this, ALL changes with a transform of your local GO will automatically be synchronized for all players! more info here
Good luck!)