Modifying the InstructionsController

The InstructionsController will handle the AR and anchor modes for the app. Now we'll edit the InstructionsController script (component of Game Controller in the scene). Open the script for editing and change it as follows:

File: InstructionsController.cs

At the top of the class, add the following public and private variables:

    public GameObject standardContent;
private bool arMode;

public GameObject anchorButton;
public GameObject arPrompt;
private bool anchorMode;

Add the following methods to toggle the AR mode:

    public void ToggleAr() {
arMode = !arMode;
if (arMode) {
TurnOnArMode();
} else {
TurnOffArMode();
}
}

void TurnOnArMode() {
standardContent.SetActive(false);

TurnOffAnchorMode();
}

void TurnOffArMode() {
standardContent.SetActive(true);

anchorButton.SetActive(false);
arPrompt.SetActive(false);
}

Lastly, add the following methods to toggle the set-position anchor mode:

    public void ToggleAnchor() {
anchorMode = !anchorMode;
if (anchorMode) {
TurnOnAnchorMode();
} else {
TurnOffAnchorMode();
}
}

void TurnOnAnchorMode() {
anchorButton.SetActive(false);
arPrompt.SetActive(true);
}

void TurnOffAnchorMode() {
anchorButton.SetActive(true);
arPrompt.SetActive(false);
}

The script exposes the public methods ToggleAr() and ToggleAnchor() that will be wired to screen buttons for switching modes and showing/hiding UI elements on the screen.

Save your changes.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.23.101.60