Billboard - jimdroberts/FishMMO GitHub Wiki
The Billboard
component ensures that a GameObject always faces the camera, creating a billboard effect. It can be configured to match the camera's full rotation or only the Y-axis, making it useful for UI elements, nameplates, or sprites that should always face the player in the FishMMO client.
-
private Camera Camera
Reference to the camera used for billboarding. The object's rotation matches this camera.
-
public bool PivotYAxis
If true, only the Y-axis (vertical) rotation is matched, creating a horizontal billboard effect.
-
public Transform Transform { get; private set; }
Cached transform of the camera. Used for efficient access to camera orientation.
-
void Awake()
Called when the script instance is being loaded. Sets the camera reference.
-
void LateUpdate()
Called after all Update functions have been called. Updates the object's rotation to match the camera.
-
public void SetCamera(Camera target)
Sets the camera to use for billboarding and caches its transform. Parameters: - Camera target: Camera to use for billboarding.
- Attach the
Billboard
component to any GameObject you want to face the camera. - Ensure the GameObject is part of a scene with a valid Camera tagged as MainCamera.
- Optionally, set
PivotYAxis
to true in the Inspector to restrict billboarding to the Y-axis only. - The component will automatically use the main camera, or you can assign a specific camera via script using
SetCamera
.
// Example 1: Basic Billboard Usage
// Attach this script to a GameObject in the scene.
// The object will always face the main camera.
// No additional code required; the component works out of the box.
// Example 2: Assigning a Custom Camera
// Assign a different camera for billboarding at runtime.
Billboard billboard = GetComponent<Billboard>();
billboard.SetCamera(myCustomCamera);
- Use
PivotYAxis
for objects that should only rotate horizontally (e.g., nameplates). - Ensure the camera reference is valid; the component will attempt to recover if the camera is lost.
- Use this component for UI or world-space elements that must always face the player for clarity.