I am trying to make a randomly selected player to sync the same person to teleport as the chose ‘death’ team using Photon 2.
What it does currently is: if I use two clients it will choose the opposite client to teleport, therefore not being synced and they eventually interpolate back to their original position if i don’t move the player.
using Photon.Pun;
using UnityEngine;
public class GameStarter : MonoBehaviour
{
private bool shouldTimerRun = true;
private float startTime;
private float time;
[SerializeField] private float timeToStart = 5f;
private int deathIndex;
private int spawnPicker;
public PlayerController[] players;
void Start()
{
startTime = Time.time;
}
// Update is called once per frame
void Update()
{
players = FindObjectsOfType<PlayerController>();
if (shouldTimerRun)
{
time = Time.time - startTime;
if (time >= timeToStart)
{
GetComponent<PhotonView>().RPC("RPC_SetTeams", RpcTarget.All);
}
}
}
[PunRPC]
private void RPC_SetTeams()
{
time = 0f;
shouldTimerRun = false;
deathIndex = Random.Range(0, players.Length);
spawnPicker = UnityEngine.Random.Range(0, GameSetup.GS.deathSpawnPoints.Length);
var death = players[deathIndex];
death.transform.position = GameSetup.GS.deathSpawnPoints[spawnPicker].transform.position;
}
}