Skip to end of metadata
Go to start of metadata

You are viewing an old version of this content. View the current version.

Compare with Current View Version History

Version 1 Next »

Demonstrates how to configure a usable barcode reader that shines a light on activation. Uses this Barcode Scanner asset as a base:

https://assetstore.unity.com/packages/3d/props/electronics/barcode-scanner-177384

Scene Object

To start, we’ll add a Motive Scene Object to the “main” part of the scanner since this is the part the user will be using:

Pick up the Scanner

Now we want to make the main part of the reader grabbable. Right-click “main” and choose “Make Grabbable” from the Motive menu:

You’ll notice that when you grab from a distance, the grip is far too low on the handle. Let’s add a grab anchor to fix that:

Assign this object to the Grab Anchor property on the Grabbable:

Next, we’ll add a light that we can turn on when the scanner is being grasped and the trigger is held down. Add a Spot Light like this:

You can adjust the light settings to fit your needs. Note that the light is disabled by default.

Now let’s connect an Action on the Grabbable to turn this light on & off. Connect Grab Trigger Down and Grab Trigger Up to enable & disable the light:

The scanner should now shine a light while the trigger is held down:

Finally we can make this Usable by adding a Point and Shoot action:

See Usable World Objects for more information about Usables. This action fires when the user points at an object and pulls the trigger. It uses a raycast. We want the raycast to originate from the light source, so let’s set the Raycast Transform:

Attach to Base

With these settings, the scanner will return to its base after you drop it, but sometimes the user will simply want to place the scanner back in its cradle. We can achieve this by making the scanner Attachable and making the base an Attachable Receiver.

  1. Right-click on “main” to “Make Attachable”.

  2. Right-click on “base” to “Make Attach Receiver”.

  3. Drag “base” onto the “Attached To” field of “main”. This assigns “base” as the default Attach Receiver for “main”.

Now when you reach to replace the scanner, you’ll see a highlight indicating that you can place it back in the base. However, with this configuration, you’ll likely notice that the highlight flashes on and off. This is because both base and main have been assigned mesh colliders by the Motive builders. Unity does not handle collision detection between mesh colliders very well. To alleviate that, let’s replace the mesh collider on base with a box collider:

With this in place, the collision detection will be much smoother and the highlight will be more stable.

  • No labels