You are developing a 2D platformer. Create a scene containing:
- Player (a cube or sprite with
Rigidbody2DandBoxCollider2D) - Finish trigger (
BoxCollider2DwithIsTriggerflag) - Trap (e.g., a falling spike or enemy)
- Secret door (an object that should disappear or open)
- Audio manager (an object with an
AudioSourcecomponent)
public UnityEvent OnPlayerReachedFinish;This event should be invoked when the player enters the finish trigger.
Do not add any direct references to other objects (Light, Door, Audio, etc.) in this script.
- Play victory sound (call
AudioSource.PlayOneShot()orPlay()on the audio manager) - Activate the trap — enable a component that makes the trap dangerous (e.g.,
Behaviour.enabledorGameObject.SetActive(true)) - Deactivate the secret door — disable its
GameObject(or play an opening animation) - Display text "Level complete!" (use
TextMeshProorUI.Text)
Create a second script ScoreCounter.cs with a public method AddScore(int value). Bind it to the same event, but pass a parameter of 5 points.
Hint: UnityEvent allows you to select a method with an int parameter — a value input field will appear in the Inspector.
- The
PlayerTriggerHandlerscript has no variables of typeLight,Door,AudioSource,Text, etc. - All reactions to the event are configured only through the Inspector.
- When the player enters the finish trigger, simultaneously:
- A sound plays
- The trap activates
- The door disappears / opens
- Text appears (and points are added if the bonus task is completed)
Don't forget to click "+" in the event's Inspector field for each action. You can bind multiple methods to a single event — they will execute from top to bottom.