I have big problem in my code .. I want to spawn obstacle exactly on the same position as on the server is spawned so I made rpc Method and tried to pass random variable of float , but when i run the game obstacles are spawned on the diffrent position. I am loosing a lot of time to get it done but I still can not find solution.
Here is the code
[PunRPC]
void RPC_SpawnColumn(Vector3 position)
{
// Instantiate(prefab, position, Quaternion.identity);
Debug.Log("THIS IS SPAWNYPOSITION" + spawnYPosition);
Instantiate(prefab, new Vector2(9, spawnYPosition), Quaternion.identity);
}
private void OnTriggerEnter2D(Collider2D collision)
{
//print("Are we here");
if (collision.GetComponent<ColumnsMultiplayer>() != null)
{
print("Or are we here");
if (SpawnOnce)
{
spawnYPosition = Random.Range(-3.36f, 2.98f);
photonView.RPC("RPC_SpawnColumn", RpcTarget.Others,new Vector3(9, spawnYPosition)); // this is
}
//SpawnColumn();
SpawnOnce = false;
}
}
Thank you so much for reading post.
Edit: I need to send spawnYPosition from method two to method one and spawn it with same position of spawnYPosition in the second method.
position
argument in the RPC call, but none of your code in that method actually reads or uses thatposition
variable. Is this intentional? Have you tried actually reading & using the value that was passed from the caller? \$\endgroup\$