I use Photon Network to Instantiate an object in the scene, but then I want to save it’s position in an other script.
try
{
//Load Player
PlayerData data = SaveSystem.LoadPlayer();
Vector3 position;
position.x = data.position[0];
position.y = data.position[1] + 2f;
position.z = data.position[2];
Debug.Log(position.ToString());
GameObject player = PhotonNetwork.Instantiate(playerPrefab.name, position, Quaternion.identity);
Debug.Log("Instantiated new Player from save file");
}
catch (System.Exception)
{
Debug.LogError("Couldn't find any save file, creating one");
Vector3 randomPosition = new Vector3(Random.Range(minX, maxX), 3, Random.Range(minZ, maxZ));
GameObject player = PhotonNetwork.Instantiate(playerPrefab.name, randomPosition, Quaternion.identity);
throw;
}
But the problem is that I can’t get the variable “player” elsewhere, I get an error saying that :
The name 'player' does not exist in the current context [Assembly-CSharp]
The other way I tried saving the position is by using the PlayerPrefab’s position, but it never changes, and so doesn’t match the player’s real-time position