// +++ life cycle +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ public StateOutOfBounds(GameObject go) { // collect references and store them localy // for ease of use ballScript = go.GetComponent <nvp_Ball_scr>(); ballConfig = ballScript.ballConfig; transform = ballScript.transform; }
// +++ life cycle +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ public StateMoving(GameObject go) { // get observed component ballScript = go.GetComponent <nvp_Ball_scr>(); ballConfig = ballScript.ballConfig; // collect references from the ballscript // that are needed to access within this behavior currentSpeed = ballConfig.startSpeed; ballTransform = ballScript.transform; }
// +++ event handler ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ void onBallHitsWall(object sender, object eventArgs) { nvp_Ball_scr ball = (nvp_Ball_scr)sender; transform.position = ball.transform.position; if (transform.position.x < 0) { leftWallParticleSystem.Play(); } else { rightWallParticleSystem.Play(); } }