Platformer visual script tour
Trace four real Platformer methods from their diagrams to the exact C# statements that drive the game.
On this page
This tour reads four methods from the Platformer sample, a sample from the optional Round Trip Sample - Platformer package that you install and import into a test project. They are the sample’s own methods, chosen because they show common flow patterns; your project’s classes will differ, and the same reading applies to them once their folder is indexed.
Four methods tell most of the sample game’s story. Read the white execution wire first, then compare each node with the source statement below it. The snippets are the sample’s real method bodies with their inline comments; the documentation comments above each method are left out.
CollectCoin
Section titled “CollectCoin”The first branch refuses a null or already collected coin. The second check refuses to proceed without the score counter and HUD; Round Trip lists it on the method’s GUARDS card in the right rail, so it has no node on the canvas. The successful path then calls three kinds of object: the coin supplied by the collision, score and HUD components in the scene, and an optional audio service connected during setup.
Read the calls left to right. coin.Collect() makes the coin ignore repeated collection attempts. AddCoins changes shared progress. RefreshCoins presents the new values. _audio?.PlayCoin() runs only when the optional service exists.
StompEnemy
Section titled “StompEnemy”The opening guard makes a second stomp do nothing. State and movement happen before scoring, so the enemy still falls and the player still bounces when the scene’s score counter reference is absent.
The _rules.stompScoreValue GET pill is the useful data trail. Follow it into AddScore to see that the amount comes from the LevelRules asset, not a hidden literal on the canvas.
OnCoinCountChanged
Section titled “OnCoinCountChanged”This method is called once during configuration and after every coin change. Missing references keep the goal closed in the HUD. With both references present, a rule that does not depend on scene objects checks whether the count meets the threshold.
The local shouldUnlock feeds both presentation and behavior. The HUD stays open after the door opens because its condition also reads _door.IsUnlocked. The final branch calls Door.Unlock only when the rule returns true, and CoinUnlockRule.ShouldUnlock is one line: coinCount >= threshold. Change coinUnlockThreshold on the LevelRules asset and the same visual script opens the goal after a different number of coins.
ApplyState
Section titled “ApplyState”ApplyState turns an enum into behavior. Patrolling enables movement and collision. Stunned stops movement while leaving the body present. Defeated stops movement, disables the body collider, and swaps the visual.
The switch node is the map. Each case names a state, and the helper calls keep the nodes readable without hiding the exact method sequence.
Following the tour in the test project
Section titled “Following the tour in the test project”- In the test project where you imported the sample, check that its
Platformer/Runtimefolder is listed in the class picker. Round Trip adds it when you import the sample; if you removed it, add it again with Assets > Round Trip > Add Folder to Round Trip. - Open each method in the order on this page.
- For every branch or switch, say which data pin chooses the path before reading the source.
- Double-click the active method title to open the same method in your code editor and check the statement order.