Rpc parameters
The whole answer can be found below.
Try Our
Documentation
Please check if you can find an answer in our extensive documentation on PUN.
Join Us
on Discord
Meet and talk to our staff and the entire Photon-Community via Discord.
Read More on
Stack Overflow
Find more information on Stack Overflow (for Circle members only).
Rpc parameters
Zeohack
2021-06-30 07:49:46
hi.. I've been dealing with rpc for a while, but I couldn't figure out how to write method parameters, especially piece and Vector2Int gridpoint parameter method, how should I write them when calling the method with rpc? I will be glad if you help. here are my codes..
MoveSelector Script..
Void Start(){
Pw = GetComponent<PhotonView>();
}
Void Update(){
Ray ray = cam.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray, out hit))
{
Vector3 point = hit.point;
Vector2Int gridPoint = Geometry.GridFromPoint(point);
//
if (pw.RPC("PieceAtGrid",RpcTarget.All, gridPoint) == null)
{
pw.RPC("CapturePiece",RpcTarget.All, piece, gridPoint);
}
}
Gamemanager Script...
[PunRPC]
public void CapturePiece(gameObject piece, Vector2Int gridPoint)
{
//
//
}
[PunRPC]
public GameObject PieceAtGrid(Vector2Int gridPoint)
{
if (gridPoint.x > 7 || gridPoint.y > 7 || gridPoint.x < 0 || gridPoint.y < 0)
{
return null;
}
return pieces[gridPoint.x, gridPoint.y];
}
Geometry Script...
public class Geometry
{
static public Vector3 PointFromGrid(Vector2Int gridPoint)
{
float x = -3.5f + 1.0f * gridPoint.x;
float z = -3.5f + 1.0f * gridPoint.y;
return new Vector3(x, 0, z);
}
static public Vector2Int GridPoint(int col, int row)
{
return new Vector2Int(col, row);
}
Comments
Vector2Int is not a type that PUN de/serializes out of the box. It needs to be added as custom type (or you use Vector2).
What are the issues you run into?
I need to use the gridpoint parameter to call the method, how can I add it as a custom type?
Have a look at CustomTypesUnity.cs. It registers a few types of Unity as custom types for Photon.
There is also a doc about serialization in PUN.
thanks I think I need to adapt it to my project as Vector2Int by looking at Vector2 examples
Back to top