Teleporter - jimdroberts/FishMMO GitHub Wiki
Represents a teleporter interactable that can transport players to a target location. Inherits from Interactable and provides a target Transform for teleportation.
-
public Transform Target
The target location to which players will be teleported.
-
public override string Title { get; }
Gets the display title for this teleporter, used in UI elements.
-
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)
- Attach the Teleporter component to an interactable GameObject in your scene.
- Assign a target Transform to the Target field in the Inspector.
- The teleporter will transport players to the target location when interacted with.
// 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);
- 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.