SceneTeleporter - jimdroberts/FishMMO GitHub Wiki

Description

MonoBehaviour for scene teleporters. Handles teleportation logic on the server and draws gizmos for visualization in the editor.


API Access

Fields

  • public Color GizmoColor

    The color used to draw the teleporter gizmo in the editor.

Methods

  • 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.

Basic Usage

Setup

  1. Ensure the script is attached to a GameObject with a Collider component set as a trigger.
  2. Assign the desired color to GizmoColor in the Inspector (Editor only).
  3. The GameObject should be named according to the teleportation destination logic.
  4. The player character must implement IPlayerCharacter and have a Teleport(string destination) method.

Example

// 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.

Best Practices

  • 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.
⚠️ **GitHub.com Fallback** ⚠️