53 lines
1012 B
C#
53 lines
1012 B
C#
using Godot;
|
|
using System;
|
|
|
|
public partial class TimescaleSystem : Node
|
|
{
|
|
[Export] public double SlowLength = 1.0;
|
|
[Export] public double SlowMagnitude = 0.2;
|
|
|
|
Node controller;
|
|
|
|
public override void _Ready()
|
|
{
|
|
controller = GetNode<Node>("/root/ControllerEventBus");
|
|
|
|
Callable callable = new Callable(this, MethodName.OnControllerContact);
|
|
|
|
controller.Connect("new_target", callable);
|
|
|
|
this.OnControllerContact(this);
|
|
}
|
|
|
|
|
|
public void OnControllerContact(Node node)
|
|
{
|
|
GD.Print("toUCHED!");
|
|
|
|
Engine.TimeScale = this.SlowMagnitude;
|
|
|
|
Timer timer = new Timer();
|
|
timer.Name = "SlowTimer";
|
|
|
|
this.AddChild(timer);
|
|
|
|
timer.WaitTime = this.SlowLength * this.SlowMagnitude;
|
|
timer.OneShot = true;
|
|
|
|
timer.Timeout += () => {
|
|
GD.Print("TimE!");
|
|
Engine.TimeScale = 1.0;
|
|
timer.QueueFree();
|
|
};
|
|
|
|
|
|
|
|
|
|
timer.Start();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|