# We are creating a script attached to the Trigger device. # "this" refers to the Trigger itself. using { this } # This is our Function. Think of it as a custom move in your fighting game. # We define it once, and call it later. spawn_car := func(): # 1. Find the Spawner device by its name in the editor. # 'Find' looks through the Scene Graph for an object named "Spawner_01". spawner := Find("Spawner_01") # Safety check: If we can't find the spawner, stop here. # This prevents the game from crashing if we made a typo. if (spawner == None): return # 2. Use the Spawner's built-in function to spawn the vehicle. # 'Spawn' is a method that comes with the Vehicle Spawner device. # It creates the car entity in the world. spawned_vehicle := spawner.Spawn() # 3. (Optional) Do something with the car immediately. # For example, we could lock the doors or set a timer. # Here, we just print a message to the debug console to prove it worked. Print("Car spawned! Ready for war.") # This is an Event. Events are like ears that listen for specific actions. # OnBeginPlay runs once when the game starts. OnBeginPlay := func(): Print("Race is on! Watch for the trigger.") # This Event listens for when a player enters the Trigger. # 'Player' is the person playing the game. # 'Trigger' is the device we attached this script to. OnBeginPlay := func(): # We want to listen for the 'OnBeginOverlap' event of the Trigger. # This means: "When something starts touching this trigger..." trigger := Find("Trigger_01") # Make sure your trigger is named this in editor! if (trigger != None): # Connect our function to the trigger's event. # Whenever the trigger fires, call spawn_car(). trigger.OnBeginOverlap += func(player: Player): spawn_car()