Pun 2 Simple build system Error
Options
Hi! im trying to create a extremly simple build system, and it all works fine with only one play in the room but when a second player joins the room it doesnt work anymore. It instantiates the gameobject in the wrong position.
Here is my Update function which checks for the raycast
And here is the Instantiation RPC code
Thank you for help
Here is my Update function which checks for the raycast
void Update()
{
if (PV.IsMine)
{
if (Input.GetMouseButtonDown(0) && Canbuild == true)
{
RaycastHit hitInfo;
Ray ray = cam.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out hitInfo))
{
PV.RPC("RPC_PlaceCarrot", RpcTarget.AllBuffered, hitInfo.point, 0);
}
}
}
}
And here is the Instantiation RPC code
[PunRPC]
private void RPC_PlaceCarrot(Vector3 HitInfo, int ObjectID)
{
Vector3 BuildPosition = grid.GetNearestPointOnGrid(HitInfo);
if (ObjectID == 0 && !EventSystem.current.IsPointerOverGameObject())
{
GameObject Carrot = PhotonNetwork.InstantiateSceneObject(Path.Combine("Placeables", "CarrotPrefab"),
BuildPosition, Quaternion.identity, 0);
Canbuild = false;
}
}
Thank you for help
0