P3-SDK 0.9
P3 Software Development Kit
Loading...
Searching...
No Matches
Adding Game Content

Popup Scores

It's helpful to show the player how much a target they hit was worth. Ideally, it's best if the score values appear near the target where that score was achieved. This ability is supported by the popupScores member (which is an instance of PopupScoreController).

All SceneController and P3Aware descendants have a popupScores member which can be told to spawn a visual score popup. Remembering that the responsibility of keeping score and determining a target's point value lies with the mode layer, this is usually in response to a mode event which passes the target's value into the handler.

public void TargetHitEventHandler(string eventName, object eventObject) {
long score = (long)eventObject;
popupScores.Spawn("Nice shot!", score);
}

This example above handles an event, interprets the event data as the target's point value, then spawns a score popup with that value and the phrase "Nice shot!", to appear at the screen center.

popupScores.Spawn() has many overloaded signatures, including the ability to specify the screen location where the popup first appears, the location that it drifts towards, what speed it drifts at and how long it should stay onscreen. Positions can be referenced as Vector3 or as named locations. See PopupScoreController and Named Locations.

Spawn instantiates a prefab for the popup, called <AppCode>ScorePopup (e.g. P3SAScorePopup). There is a script component of the same name attached to it. This component descends from ScorePopup so it knows how to move according to the Spawn call that created it.

The visual appearance and behaviour of the popup score can be customized for your app. You can modify the prefab by adding, say, an interesting particle effect. In the prefab script component, the overridden AfterInitialization method can be used to decide if the particle system should be used or not.

See also
Classes P3Aware, SceneController and PopupScoreController.

Named Locations

Several overloaded signatures of popupScores.Spawn allow you to specify a named location for the popup to appear at and drift towards.

The named locations are specified in two prefabs: P3NamedLocations and another prefab called <AppCode>NamedLocations (e.g. P3SANamedLocations). These prefabs get automatically created by the SceneController so that they are in every scene for reference by popupScores.

P3NamedLocations contains some helpful locations that are part of the standard P3 layout. When your app is running, you can see these locations and their names under the P3NamedLocations (Clone) object in the scene Hierarchy. Some examples of locations are:

  • screenCenter
  • playableLCDCenter
  • upperCentral
  • flipperGap
  • sideTarget0 (also 1-7)
  • scoop0 (also 1-7)
  • lcdCorner0 (also 1-3)

You can add empty game objects to your NamedLocations prefab (e.g. P3SANamedLocations.prefab). The names and locations of those empty game objects will automatically be found by the PopupScoreController so you can reference those locations by name in popupScores.Spawn(). Some of your locations will likely be in the upper playfield area which is off screen. You can still use these named locations, but your popup scores might take some time to drift into the visible area of the screen. Some overloaded signatures of popupScores.Spawn allow you to truncate those starting positions so that they appear at the edge of the screen initially, in the direction of your offscreen named location. See PopupScoreController.

Adding a Scene

In the Unity Editor, select "Add new scene" from the Multimorphic menu. Enter the scene name and click Continue. A new scene will be created with its own scene controller script. You can then add scene-specific code to the scene controller script.