Hi.
I’m trying to sync variables between two scenes.
The first scene is the main game in which the user can interact with objects using Razer Hydras. the second one will be build for android and will use Vuforia to create an augmented reality of the first scene.
I’m using the Network Manager to connect the two scenes and I wrote a script that should get the position of the objects of the first scene and assign them to the ones in the second scene.
The two scenes are able to connect with each other but the script isn’t syncing the variable.
The gameobject containing these scripts (NetworkManager, script) is the same on both scenes.
using UnityEngine;
using System.Collections;
using UnityEngine.Networking;
public class NetworkMana : NetworkBehaviour {
[SyncVar] //Sync variable across the network
public Vector3 syncPosmb;
[SerializeField]
float lerpRate = 15;
void FixedUpdate()
{
getPosition();
//finds if the Oculus Rift object is present, if so, this means we are the server
if (GameObject.Find("OVRPlayerController"))
{
syncPosmb = GameObject.Find("obj").transform.position; // get the object's position
}
}
void lerpPosition()
{
if (!GameObject.Find("OVRPlayerController"))//if we're not the server
{
GameObject.Find("obj").transform.position = Vector3.Lerp(GameObject.Find("obj").transform.position, syncPosmb, Time.deltaTime * lerpRate); //Set the object's position
}
}
[ClientCallback] //Executed only on clients, if I understand correctly
void getPosition()
{
lerpPosition();
}
}