Mhmm, so my 2nd player joins channel "4" and his client now "hosts" the "level". How does his client know, if it needs to create these asteroids because the system was never visited before - or, in the opposite, to simply join the channel and get the already existing gameobjects from the server(?)?
Edit 1: Okay, I am getting some wierd results now. Playing with one client, the following happens:
- Client connects, everything as intended, roid is there.
- I shoot the roid and then open the map (chance of channel)
- then I return to the space channel and the roid is once again being created.
Same effect for two players, everytime a player joins the channel, a roid is spawned. I understand that !TNManager.isThisMyObject isnt enough to ensure a one-time exceution of this code:
if (!TNManager.isThisMyObject) {
return;
}
GameObject obj = (GameObject)Resources.Load("Prefabs/Objects/AsteroidL");
TNManager
.Create(obj,
new Vector3
(0,
0,
20), transform
.rotation,
true);
How can i prevent this effect? Do I need to implement some kind of "createStuff"-flag for every channel and set it to false after executing it once?! What will happen when everybody leaves the channel a another client relogs? Is there any way to manage/store this on the server and query it when every client tries to execure this code, otherwise each joining client won't know if it must create the gameobject or not.
Edit 2: Next question - "Persistent"/static player object.
My player switches from the game- to the galaxymap-channel. There he selects another star system and then goes back to the game-channel. How can I get the information about the selection or player information in general from channel to channel? I thought the TNNamager.Plaers.Data would be the way to go, but this class wont do the job since the actual player isnt contained in the list. I also tried the GamePlayer-Object from the tutorial (static variable), but that doesnt seem to work either, after switching the scenes, all values in my GamePlayer-Object are lost...
This is my player-Object:
public class ActPlayer : MonoBehaviour {
static public ActPlayer instance;
public StarSystem selectedSystem;
public Vector3 playerPosition;
void Awake ()
{
if (TNManager.isThisMyObject) {
instance = this;
}
}
}
And this is how I want to retrieve the value:
public class SysUpdateSelText : MonoBehaviour {
public GUIText actSelGalMap;
// Update is called once per frame
void Update () {
if (ActPlayer.instance.selectedSystem != null) {
actSelGalMap.text = ActPlayer.instance.selectedSystem.sysName;
} else {
actSelGalMap.text = "No selection";
}
}
}
The ActPlayer.cs is attached to the scenes main cameras.
Thanks again for your help ArenMook, I really appreciate your work!