Tutorial: Select Items Programmatically

NOTE: This tutorial works with version 1.7+ of the Mobile Touch Camera asset.

This topic is about selecting and deselecting Mobile Touch Pickables programmatically via C# script code. Both actions basically require just 1 line of code.

mobilePickingController.SelectCollider(itemCollider);
mobilePickingController.DeselectSelectedCollider();

There are just a few things to note. First, you are required to get a reference to the Mobile Picking Controller component. In the above this reference is named mobilePickingController. Second, the SelectCollider method requires you to give the collider component of the pickable item you want to select programmatically. In the above this collider is named itemCollider.

Caution when invoking the SelectCollider code from a user-click on a UI button. In this case you need to add to the button an Event Trigger component and set its Pointer Down event to the TouchInputController.OnEventTriggerPointerDown method that is typically found on the camera Game Object. Otherwise the click on the button may first invoke the selection code, but then immediately deselect the item because of the user clicking somewhere.

Advertisements