Hello there! I’ve got a question for my little MMO that I’m trying to create:
“Zone Walls”
If you’ve played Everquest (1), you’d know all about those Zone Walls. You walk up to them, and it loads another area in the game, and places you inside it. But, How would I go about placing it into my game as well? 
Thanks! 
(If codes are given, please use Javascript!)
Here is my logic… I’m sorry I’m not a big Javascript person so I didn’t want to give you bad syntax, but here is the logic in simple C#… This code assumes that your player is persistent between loading levels. (i.e. a script in the player object runs this function DontDestroyOnLoad(this); ).
The logic is:
- When a player enters a ZoneGate store that gates ID and load a new scene
- When the new scene loads all the gates check if their ID matches the last gate’s id that the player entered
- If the id matches a gate move the player to that new gate’s position
So if you attach this script to an empty game object with a collision box and make it a prefab, you can just put this around your scene and set their “id” in the editor… you could make it more robust by having each gate have an “id” and a “destinationID” if you get complex with your zone gates.
using UnityEngine;
using System.Collections;
public class ZoneGate : MonoBehaviour
{
public int id;
// When you load a new level this method will be called by each gate
void Start()
{
//Make sure a gate was entered. A good check for first zone.
if( PlayerPrefs.HasKey("LastGateEntered") )
{
//Each gate will check if their id matches the id of the
//gate the player entered.
if(PlayerPrefs.GetInt("LastGateEntered") == id)
{
//If the id matches than set the player's location to my location
GameObject player = GameObject.FindGameObjectWithTag("Player");
if(player != null)
{
player.transform.position = transform.position;
}
else
{
Debug.LogError("An object with the tage 'Player' could not be found!");
}
//NOTE: If your player object is not persitant between LoadLevel, then
//just instantiate a player at this location instead of setting its position.
}
}
}
//Called when any object enter this area
void OnTriggerEnter(Collider other)
{
//Check if the other object is the player
if(other.gameObject.CompareTag("Player"))
{
PlayerPrefs.SetInt("LastGateEntered", id);
Application.LoadLevel("SweetNewZone");
}
}
}