• Register
Post tutorial Report RSS Gentrification: The Code, Not Clicking Past UI

A simple tutorial on how to stop the objects behind the UI from reacting to clicking when the player interacts with the UI.

Posted by on - Basic Client Side Coding

Header

I wanted to make a few small tutorials to solve issues I’ve run into while working on this game. Gentrification is built entirely with Unity Visual Script, which is usually fairly straightforward and user-friendly, but sometimes less than ideally documented. I’ve decided to start writing short tutorials on things I banged my head against. This is an overview on how to block the player from clicking on background game objects while trying to press buttons in the UI.

Problem

Recently I built a minigame in Gentrification called Urgent Mail where the player has to click on little email icons scattered around the UI. The problem was, the screen is constantly filled with other intractable objects behind the UI. Instead of focusing on the minigame, players were accidentally selling apartments, putting themselves into debt, and quitting the game.

Solution

So, I had to add a check in the script of all clickable objects in the main screen. The script is fairly simple. I just had to add in a single “Is Pointer Over Game Object” block and an “If” switch to regulate it.

How To

The “Is Pointer Over Game Object” block needs to be attached to the Event System that was created along with the canvas you’re working in. Should be preloaded in your hierarchy. In this case, you can see me pulling it into the script with an AoT list.

That’s really it. Short, sweet, simple, saves a lot of head-banging. If you want to hear more about this game, join the Discord here or follow the Kickstarter here. If you want more bite-sized tutorials on Unity Visual Script, make sure to follow me here and I will be back with more.

Thanks,

-Andrew

Post a comment

Your comment will be anonymous unless you join the community. Or sign in with your social account: