SceneTeleporter - jimdroberts/FishMMO GitHub Wiki
MonoBehaviour for scene teleporters. Handles teleportation logic on the server and draws gizmos for visualization in the editor.
-
public Color GizmoColor
The color used to draw the teleporter gizmo in the editor.
-
void OnDrawGizmos()
Draws a gizmo at the teleporter position for visualization in the Unity editor.
-
void OnTriggerEnter(Collider other)
Called when another collider enters the teleporter's trigger. Teleports the player character if valid and not already teleporting. Parameters:
- Collider other: The collider that entered the trigger.
- Ensure the script is attached to a GameObject with a Collider component set as a trigger.
- Assign the desired color to
GizmoColor
in the Inspector (Editor only). - The GameObject should be named according to the teleportation destination logic.
- The player character must implement
IPlayerCharacter
and have aTeleport(string destination)
method.
// Example 1: Teleporter Setup in Unity
// Attach SceneTeleporter to a GameObject with a Collider (set as trigger).
// Set GizmoColor in the Inspector for editor visualization.
// Ensure the GameObject's name matches the teleport destination identifier.
// Example 2: Player Character Teleportation
// When a player character (implementing IPlayerCharacter) enters the teleporter's trigger collider,
// OnTriggerEnter will call character.Teleport(gameObject.name) if not already teleporting.
- Always ensure the Collider is set as a trigger for teleporters.
- Use unique GameObject names for each teleporter to avoid destination conflicts.
- Implement proper checks in the player character's Teleport method to handle edge cases.
- Use GizmoColor for clear editor visualization of teleporter locations.