Setting up a Player prefab to auto-detect Hotspots

By default, Hotspots are detected by hovering the Cursor over them. Alternatively, Hotspots can be detected by their proximity to the Player. This is especially useful for games played with a Touch-screen or keyboard, where using a Cursor is difficult.

Begin by going to the Settings Manager, and changing the Hotspot detection method to Player Vicinity. If you are making a game with Direct- or First Person-control, you will be shown a new field: Hotspots in vicinity. When left at it's default value of Nearest only, only the Hotspot closest to the Player will be detected.

If changed to Cycle Multiple, the Player will be able to switch between different Hotspots in his vicinity, similar to the controls in Grim Fandago. However, you will need to declare two new Input axes: CycleHotspotsLeft and CycleHotspotsRight.

The Inputs can be added to the InputManager (found in Edit -> Project Settings -> Input) and can be set up as follows, amending the Positive Button values with the keys of your choosing.

Assuming we've already got a Player prefab to work with, place it at the centre of your scene by dragging it in from your resources folder. We'll be detecting Hotspots around the Player with a Sphere Collider, so begin by creating a new empty GameObject. From the top toolbar, choose GameObject -> Create Empty.

With the empty GameObject selected, add the Collider to it by again going to the top toolbar and choosing Component -> Physics -> Sphere Collider.

Inside the Collider's Inspector, check the Is Trigger checkbox, and rename it to HotspotDetector. Then add the DetectHotspots component to it.

In the Scene window, you should see the Collider's influence represented by a green sphere. The Player will only be able to "see" Hotspots that are inside this sphere, so adjust it's position and size to that it covers an appropriate volume - with the centre just in front of the player.

Now make the Collider a child of the Player prefab by dropping one onto the other in the Hierarchy window.

In the Player Inspector, find the Hotspot detector child field at the bottom and drag the HotspotDetector object onto it. Apply the changes to the prefab by clicking Apply at the top, and remove it from the scene. Your Player will now highlight Hotspots as he moves around the scene.

As a final note, be aware that Unity requires a Rigidbody component to be present on at least one Collider involved for a Trigger to work - therefore, if your Player prefab doesn't have one on the base object, be sure to add this component to your HotspotDetector, and disable gravity on it.

Adventure Creator and this website are copyright Chris Burton, ICEBOX Studios

Go to top
Do NOT follow this link or you will be banned from the site!