➡️Quick Start
v1.0
Last updated
v1.0
Last updated
Getting working local time scales is fairly quick, and can be accomplished in just a few steps.
Start by ensuring your class implements IHaveLocalTime
, or inherits from MagicTimeUser
. Below, our "Sphere" class inherits from MagicTimeUser
, so has exposed fields and helpful methods ready to go.
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.
Create an empty object and add the MagicTimeManager
component to it. Add any default TimeScales to this, such as the "Global" one created in the last step.
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.
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.
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.
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
.
In the demo scene, there are two 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.
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.
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.