Portals on the global map

Hello everybody! I would like to share my solution for using portals.
I created a small map, something like Mount & Blade.
To return to the map, near the village (or other place that was entered), I added a field with the name of the portal to the script, and I search for it.
I would like to know your opinion, is this decision correct?

 [SerializeField]int nextScene;
        [SerializeField] Transform spawnPoint;
        [SerializeField] string portalName;


        Portal GetOtherPortal()
        {
            foreach (var portal in FindObjectsOfType<Portal>())
            {
                if (portal.name == portalName) return portal;
            }

            return null;
        }

2021-04-10_21-13-50

1 Like

I’m not sure if it is correct but I will say that it is really cool that you are playing with portals.

I have an old saying, “if it works, it’s correct.” :slight_smile:
In a lecture or two, we use an Enum identifier system, but that’s by no means mandatory. As long as you have a reliable way of identifying the destination, you’re good to go.

This approach seems very solid.

It allows for in level portals as well as entrance and exit.

Seems using the string name for the root object, I am also curious if you need to use the Portal position for moving player to portal within the level?

It would be nice to see that OnTriggerEnter procedure here. tks

Privacy & Terms