Loading A Random Map



  • Hi Rebound Games,

    I would like to implement a "random map" feature to my game and looking for your guidance on how to add this mechanism.

    Thanks



  • Hi,

    the NetworkManagerCustom script in the Intro scene holds your current online scene.

    If you have multiple online scenes, you could create your own script that holds an array of all available scenes. Then, at runtime, choose one of these scenes (random, or with several UI buttons that each represent one scene for the user to decide) of that array and assign its scene value to the NetworkManagerCustom online scene variable.

    If the user is about to create a new room (there are no other rooms or all rooms are full), the new room will be created using this online scene.

    Also see this thread for reference.



  • HI,
    I solved it like this. This is method in NetworkManagerCustom script.

    public override void OnCreatedRoom()
            {
                //we created a room so we have to set the initial room properties for this room,
                //such as populating the team fill and score arrays
                Hashtable roomProps = new Hashtable();
                roomProps.Add(RoomExtensions.size, new int[RoomExtensions.initialArrayLength]);
                roomProps.Add(RoomExtensions.score, new int[RoomExtensions.initialArrayLength]);
                PhotonNetwork.room.SetCustomProperties(roomProps);
    
                //this is how i load the online scene randomly :)
    
    			onlineSceneIndex = UnityEngine.Random.Range (3, 5);
    
                PhotonNetwork.LoadLevel(onlineSceneIndex);
                
                
            }
    
    

    My levels have numbers 3,4 in build settings



  • The script would change just a tad, for Unity Networking?



  • Nearly the same - but instead of an "onlineSceneIndex" (integer) value, the NetworkManagerCustom script has a "onlineScene" (scene asset) value for the scene to load.

    So on your level buttons, you would have a separate script that holds the corresponding level as a scene asset variable. On the press of the button, this scene asset variable would be assigned to the "onlineScene" variable on the NetworkManagerCustom script. You can then load the match as usual - calling UIMain.Play().

    I have deleted your other thread since this should answer it regarding scene selection.



  • Thanks guys!!!  :)

    So I can have like 4 different  level/room maps going and the system will adjust to the user loads and add new rooms accordingly? I like the random idea, so I just name my levels in the build settings numbers for an easy way to use the range in the code? Again thanks for your assistance. :)

    So as long as I adjust usage levels in dashboard, have the appropriate network scripts attached to levels, like copying the 'game' scene, the network rooms and availability is controlled by the Unity Networking system, yes? I don't need to worry about new players and scaling the system to accommodate them?

    Do you have an example of "So on your level buttons, you would have a separate script that holds the corresponding level as a scene asset variable. On the press of the button, this scene asset variable would be assigned to the "onlineScene" variable on the NetworkManagerCustom script. You can then load the match as usual - calling UIMain.Play()." that I may look at? :)



  • So I can have like 4 different  level/room maps going and the system will adjust to the user loads and add new rooms accordingly?

    When a client creates a new room, either because all other rooms are full or because there is no room available, it will choose an online scene. Other players joining this room will simply load the same scene.

    I like the random idea, so I just name my levels in the build settings numbers for an easy way to use the range in the code?

    You wouldn't have a level button for each map when loading maps randomly though, only one play button as it is now. The play button would then choose a map randomly.

    [...] the network rooms and availability is controlled by the Unity Networking system, yes? I don't need to worry about new players and scaling the system to accommodate them?

    That's a question for Unity Networking, not our asset, but yes.

    Do you have an example of [...] that I may look at? :)

    I'm not sure what exactly you are looking for? This would be a very basic script only having one variable and one method with one line, calling the UIMain.Play() method...

    Edit: two lines, assigning the "onlineScene" variable on the NetworkManager, and calling UIMain.Play().



  • Oh ok I was expecting some complicated thing. Sounds easy enough. Thanks  a million!



    HI,
    I solved it like this. This is method in NetworkManagerCustom script.

    public override void OnCreatedRoom()
            {
                //we created a room so we have to set the initial room properties for this room,
                //such as populating the team fill and score arrays
                Hashtable roomProps = new Hashtable();
                roomProps.Add(RoomExtensions.size, new int[RoomExtensions.initialArrayLength]);
                roomProps.Add(RoomExtensions.score, new int[RoomExtensions.initialArrayLength]);
                PhotonNetwork.room.SetCustomProperties(roomProps);
    
                //this is how i load the online scene randomly :)
    
    			onlineSceneIndex = UnityEngine.Random.Range (3, 5);
    
                PhotonNetwork.LoadLevel(onlineSceneIndex);
                
                
            }
    
    

    My levels have numbers 3,4 in build settings
    *

    So where in the NetworkManagerCustom.cs do I insert this method? Is there anything I need to remove?



  • Did you actually look at the method and understand what is written there? It is for Photon... you cannot use anything of that :o

    I'm a bit confused what you want to do now, random scenes or level buttons. For random scenes it would be:

    From what you are asking, it seems like you are inexperienced with programming in general. I will still not provide finished code though, because we've delivered a template asset and this is a perfect, simple addition to do on your own.



  • Help me pls(photon)
    alt text



  • Are you using the old version with Photon PUN 1, or the new version with PUN 2?

    Also did you check your build settings for the scene index? You just copy pasted Random.Range(3,5) but is this actually correct?



  • @Baroni said in Loading A Random Map:

    re you using the old version with Photon PUN 1, or the new version with PUN 2?
    Also did you check your build settings for the scene index? You just copy pasted Random.Range(3,5) but is this actually correct?

    i use pun2
    yes, i add scene in build settings



  • In our PUN 2 version, you do not need any coding to implement random map selection. Please have a look at our pdf manual and search for the Game Scenes explanation.

    Random maps are chosen automatically for the selected game mode. For example if you add a map "TDM_Map1" and "TDM_Map2", a random map is chosen out of them. The map naming "TDM_" or "CTF_" is important - more details in the documentation.



  • @Baroni
    You can link where to read it



  • It is included in the package, in Unity. The PDF file.


Log in to reply