Game Development Reference
In-Depth Information
transform.position = new Vector3(x, y, 0);
}
We put this in a separate function so that if we need to apply offsets for the CommandBar
class for different platforms, we can do it from this central helper instead of doing it
throughout the code.
With the new helper in place, we need to replace/add the Update function that will en-
sure the bar is drawn to the correct portion of the screen's space:
void Update () {
Vector2 position = Vector2.zero;
if (anchor)
{
position = CalculateAnchorScreenPosition();
}
else
{
position = transform.position;
}
SetPosition(position.x, position.y);
}
Note
We still use the SetPosition function here as this method places the command bar rel-
ative to the position in the screen space we want it to be drawn in. This still may need fur-
ther offsetting if a particular platform is needed, such as Ouya or Xbox.
With this, each frame simply gets the intended position of the command bar, either from
the anchor point or the position set in the editor, and uses our helper function to push it to
the correct part of the screen.
Finishing off, we need to call our InitCommandButtons function in the preceding
code when the script starts:
void Start () {
InitCommandButtons();
}
Search WWH ::




Custom Search