Loading A Random Map



  • 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