Improving Upon Selection Highlighting in Our Game — Part 2


Welcome to part 2 of improving upon selection highlighting in our game, this time I will be working on the remaining improvements from where we left off last time;

  1. The arrow that highlights that the water pump is selected is currently placed too low
  2. The arrow does not disappear when walking away from the water pump
  3. The arrow should only appear for the water pump when carrying the watering can

Implementing a Position Offset for the Arrow

As you might remember, the arrow that highlights that the water pump is selected is spawned too low(actually inside the water pump) and makes it hard to see, so the first thing we are going to do is to modify the code to spawn the arrow higher when a water pump is selected.

Look closely at the base of the water pump and you will see the arrow

We will start with implementing a variable for defining the height offset for the arrow called arrowHeightOffset in ItemSelector.SpawnSelectionArrow() and applying that to the position where the arrow is instantiated.

In the Unity editor, I will try with the value 3 for the offset of the water pump and see if the value is good or not.

If at first, you don’t succeed…

After adjusting it to 3.5 instead it seems to be the perfect height, that was easy!

I also noticed that the spade has its arrow placed incorrectly, so we can add another offset for the Z-axis for that so that the arrow is placed in the middle.

In Swedish, you would say “Jag får spader!”

Bugfix — The Arrow Does Not Disappear When Walking Away From the Water Pump

Right now, the arrow doesn’t disappear when walking away from the water pump(as it should) unless you walk in range of something else that also can be selected.

Since you cannot interact with the water pump at a long distance, the arrow should not indicate that you can!

Here is the function call to remove the selection arrows:

I’ll just change it to include the layer that the water pump is using to see if it makes the arrows disappear when you go out of range:

Success! 🥳

The Arrow Should Only Appear for the Water Pump When Carrying a Watering Can

The next thing to fix is to make sure that the arrow that is spawned above the water pump only appears when carrying the watering can. This is to make it more clear to the player when you can use the water pump or not.

First, we need to check if the player is carrying the watering can, and luckily I have already created an appropriate variable for another purpose that we can use. The variable is called equippedWateringCanGameObject which checks if a watering can is equipped.

To give you a refresher from the previous article, this is what the function call to add an arrows looks like:

I’m going to add checks for the following 2 things to make sure that the arrow is shown at the right time:

  1. Is the selected item a water pump?
  2. Is the player carrying a watering can?

For the first if case, we can use the tag on the game object to check what type of item is selected.

As a proof of concept, I’ll just start with detecting if the if case for detecting the type of item works first.


Since that seems to work, let’s add code to check if the player is carrying a watering can before instantiating the arrow.

The following if case might look a bit complicated, but it states the following to make sure that the arrow is instantiated in appropriate situations.

Exactly according to plan! 🤩

This also seems to have worked, so that makes 3 out of 3 completed! ✅


This marks the end of part 2, with most likely only one part left before we continue to finish the vehicle system.

In the last part of improving the selection highlighting system, I’m going to implement the functionality to press Tab and cycle through all items in range to be able to select the right one.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Otto Wretling

Otto Wretling

Writing about game development, technology, language learning, and whatever else comes to my mind!