Teleporter - jimdroberts/FishMMO GitHub Wiki

Description

Represents a teleporter interactable that can transport players to a target location. Inherits from Interactable and provides a target Transform for teleportation.


API Access

Fields

  • public Transform Target

    The target location to which players will be teleported.

Properties

  • public override string Title { get; }

    Gets the display title for this teleporter, used in UI elements.

Methods

  • void OnDrawGizmos()

    Draws gizmos in the editor to visualize the teleporter's target location and connection. Wire cube is drawn at the target position, and a line connects the teleporter to the target. (Editor only)


Basic Usage

Setup

  1. Attach the Teleporter component to an interactable GameObject in your scene.
  2. Assign a target Transform to the Target field in the Inspector.
  3. The teleporter will transport players to the target location when interacted with.

Example

// Example 1: Setting up a Teleporter in the Unity Editor
// 1. Add the Teleporter script to an interactable GameObject.
// 2. Assign a target Transform to the Target field.
// 3. The GameObject will now act as a teleporter in the scene.

// Example 2: Accessing the title in code
var teleporter = GetComponent<Teleporter>();
Debug.Log(teleporter.Title); // Outputs: Teleporter
Debug.Log(teleporter.Target.position);

Best Practices

  • Always assign a valid Target transform to ensure teleportation works correctly.
  • Use OnDrawGizmos to visualize teleporter connections in the Unity Editor for easier scene setup.
  • Extend Teleporter for custom teleportation logic or effects if needed.
⚠️ **GitHub.com Fallback** ⚠️