Cover for the App

Studio: Score System

Studio

This project demonstrates a simple score tracking system using Niantic Studio.

This project demonstrates a simple score tracking system using Niantic Studio.

Score Counter Sample Project

This project demonstrates a simple Score Counter system using Niantic Studio. You’ll learn how to:

  • Increment or decrement a score when tapping on different entities.
  • Display and update the score on a UI element in real time.
  • Trigger simple particle effects when the score changes.

Project Structure

Below is a brief overview of the key folders and files:

├── assets/ // Additional media assets (images, models, etc.)

├── counter.ts // Main script defining the Score Counter component

├── cleanup.ts // Utility for cleaning up event listeners

└── README.md // This README file

Key Files

    • Defines the component, which manages score updates, event listeners for tap inputs, and particle effects.
    • Taps on the assigned increment/decrement entities change the score, which is shown on the .
    • Provides helper functions (, ) that remove event listeners and other references when the component is detached.

Heirarchy Entities Overview

  • counter

    • An entity that has the component added.
    • Configures references to the increment entity, decrement entity, and UI score entity.
  • Increment Entity

    • A 3D object (e.g., the purple cube) that increments the score when tapped.
  • Decrement Entity

    • Another 3D object that decrements the score when tapped.
  • Score UI Entity

    • A text-based UI element or 3D text that displays the current score.

How It Works

  1. Counter Component

    • Registered in . The ECS references three critical properties:
      • – tapped to increase the score.
      • – tapped to lower the score.
      • – the text or UI element showing the current score.
  2. Event Listeners

    • The script uses events on the increment and decrement entities to adjust the score.
  3. Score Updates & UI

    • Each time the score changes, the script calls , which updates the text on the .
  4. Particle Effects

    • The function spawns a random particle burst on whichever entity was tapped, adding an extra bit of visual feedback.
  5. Cleanup

    • When the component is removed, and ensure that event listeners and references are cleared to avoid memory leaks.

Getting Started

  1. Clone or Import This Project

    • Clone this sample project into your workspace from this page .
  2. Replace increment and decrement gemoetries with desired objects/models

    • If you change the models or names of the and objects be sure to update their references in the counter components UI drop downs.
  3. Preview

    • Click the Build button and test on your device or using the simulator. Tapping the increment/decrement objects should update the displayed score and trigger particle effects.

Customization

  • Initial Score

    • You can modify the field in if you’d like a non-zero starting score.
  • Particle Effects

    • Adjust the properties in (e.g., , , , etc.) to change the look and feel of the particle burst.
  • Score UI Styling

    • Depending on your chosen type, you can style it via Studios UI system or custom CSS if you’re using 2D HTML overlay.

Troubleshooting

  • Score Not Updating

    • Ensure you assigned the correct entities in the Inspector for increment, decrement, and score.
    • Verify that you have the component attached as a custom component to your counter object.
  • No Particle Effects

    • Check that the function has a valid sprite and that the entity supports a particle emitter.

Enjoy exploring how to track and display scores in your Niantic Lightship Studio projects!