# Quick Start

Getting working local time scales is fairly quick, and can be accomplished in just a few steps.

{% embed url="<https://youtu.be/PgsRP3bPHR4>" %}

## Create Your Class

Start by ensuring your class implements [`IHaveLocalTime`](https://infinitypbr.gitbook.io/magic-pig-games/magic-time-local-time-scale/magic-time-user/ihavelocaltime), or inherits from [`MagicTimeUser`](https://infinitypbr.gitbook.io/magic-pig-games/magic-time-local-time-scale/magic-time-user). Below, our "Sphere" class inherits from `MagicTimeUser`, so has exposed fields and helpful methods ready to go.

<figure><img src="https://2431624982-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MY3N_li2jPq7az6mYfq%2Fuploads%2Flcg6wNbdGqwtb0c0LEuH%2FScreenshot%202024-10-01%20at%2011.23.30%E2%80%AFPM.png?alt=media&#x26;token=803a263e-f0e2-4787-9e52-ed5cddf31203" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2431624982-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MY3N_li2jPq7az6mYfq%2Fuploads%2FCEKhx0Mfa2FjZ1KECB2w%2FScreenshot%202024-10-01%20at%2011.23.17%E2%80%AFPM.png?alt=media&#x26;token=57ec8d55-6a35-4d16-9e2b-e77c6eea4583" alt=""><figcaption></figcaption></figure>

## Create Project-wide Time Scales

In a new project folder to hold your Time Scale objects, right-click and select **Create/Local Time Scale/ Time Scale** to create a new `LocalTimeScale` scriptable object.

Name this one "Global" for the purposes of this walkthrough. Often you'll want a Global time scale which can influence nearly all objects in your project. You can also create any additional Time Scale objects now as well.

<figure><img src="https://2431624982-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MY3N_li2jPq7az6mYfq%2Fuploads%2FUZzpvM24EBboKsmshvAR%2FScreenshot%202024-10-01%20at%2011.29.14%E2%80%AFPM.png?alt=media&#x26;token=8a873a9c-4186-4929-b733-4f3776fc60da" alt=""><figcaption><p>The demo scene has a "Global" Time Scale, plus one for each of the RGB colors.</p></figcaption></figure>

## Add Magic Time Manager to the Scene

Create an empty object and add the [`MagicTimeManager`](https://infinitypbr.gitbook.io/magic-pig-games/magic-time-local-time-scale/magic-time-manager) component to it. Add any default TimeScales to this, such as the "Global" one created in the last step.

<figure><img src="https://2431624982-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MY3N_li2jPq7az6mYfq%2Fuploads%2Fa5MFbHNgr0YBbdwEP1Ci%2FScreenshot%202024-10-01%20at%2011.29.56%E2%80%AFPM.png?alt=media&#x26;token=5f35b66c-40fb-4d2b-a1ba-d4c5a81bf1cf" alt=""><figcaption><p>Any object can easily hook into the Initial Time Scales attached to <code>MagicTimeManager</code></p></figcaption></figure>

## Set up the Initial Time Scales for your Objects

If you're using the `MagicTimeUser`, or if you'd like to run your own method for this in your own `IHaveLocalTime` class, you'll want to populate the Initial Time Scales for your objects. This can be done on the prefabs themselves.

At runtime, the objects will subscribe to instances of these Time Scales via the Magic Time Manager class. The object will be affected by the Time Scales set here.

<figure><img src="https://2431624982-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MY3N_li2jPq7az6mYfq%2Fuploads%2F8ijhJoA1yvfdTGN4MX34%2FScreenshot%202024-10-01%20at%2011.30.50%E2%80%AFPM.png?alt=media&#x26;token=337fd9ec-d4c8-4ff8-a820-8ce4febae963" alt=""><figcaption><p>The "Red" sphere in the demo is affected by "Global" and "Red" Time Scale objects.</p></figcaption></figure>

## Implement the Time Value in Your Code

Now that we have everything set up, it's time to ensure your code is properly implementing the Time Scale values. You can get additional scripting information in the documentation pages.

<figure><img src="https://2431624982-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MY3N_li2jPq7az6mYfq%2Fuploads%2Ft2TyBw5UqilKlNES57sd%2FScreenshot%202024-10-01%20at%2011.38.59%E2%80%AFPM.png?alt=media&#x26;token=09b840b7-1287-4c12-a664-84eb69493457" alt=""><figcaption></figcaption></figure>

For the demo scene, the `SphereMovement` class controls the movement of the red, green, and blue spheres. There is a `baseSpeed` value which handles the overall default speed.&#x20;

Instead of using `Time.deltaTime` to determine the amount of movement the object should experience each frame, we will use the `sphere.DeltaTime`, which is the modified value based on the TimeScale objects the sphere is being affected by.

`DeltaTime` is a property exposed in [`MagicTimeUser`](https://infinitypbr.gitbook.io/magic-pig-games/magic-time-local-time-scale/magic-time-user).

## Optional: Set up Time Zones

In the demo scene, there are two [Time Zone](https://infinitypbr.gitbook.io/magic-pig-games/magic-time-local-time-scale/time-zone) spheres -- one will make objects move fast, the other slow. You can create a Time Zone area similar to this by adding an object with a `Collider` on it, with the "Is Trigger" value set `true`.

Then, add the `TimeZone` component to this object, and set the "Time Scale Value" to a value you'd like.

<figure><img src="https://2431624982-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MY3N_li2jPq7az6mYfq%2Fuploads%2F9kZFJRH8uCgxjL8tASzL%2FScreenshot%202024-10-01%20at%2011.41.41%E2%80%AFPM.png?alt=media&#x26;token=f9475e48-d80e-4c03-bb6a-b9f873bb615d" alt=""><figcaption></figcaption></figure>

Now, whenever an `IHaveLocalTime` object triggers the zone, the `LocalTime` instance created by the Time Zone object will affect the object. The effect is removed when the object exits the trigger area.

## Optional: Test the Demo

Test the Demo scene for yourself to experience how Magic Time operates. In the demo, colorful balls will fly around an area, passing through time zones that will speed up and slow down their motion.

The demo allows for changing the Local Time of all objects, or all objects of a specific color. Objects affected by multiple Time Zones will have the effects stacked.
