Daily progress: Adding a Shop

Esteban Ibarra
2 min readAug 27, 2021

--

Today, we’re expanding the 2D Mobile platformer to include a shop with purchasable items with the diamonds we collect! There’s a shop image already given to us so I placed it in its proper area:

To make a Shopkeeper canvas, I made a UI Canvas, canvas scaler: Scale with Screen Size, 1920x1080, ScreenSpace:Overlay. Next, I placed the graphics and buttons:

As a challenge, we are told to enable this panel when we hit the shopkeeper. Simple enough! Let’s turn the panel off.

Next, we’ll have to add a BoxCollider2D to the shop owner and set it to trigger. and of course a rigidbody2d!

Maybe we’ll extend the range of the BoxCollider2D so the panel gets triggered earlier.

We’ll create a script for the ShopKeeper and attach it to them:

The script is straightforward, we’ll make sure we’re using UnityEngine.UI, and then we’ll create a holder for the shop_panel. afterwhich we activate it with an OnTriggerEnter2D, and as a bonus, deactivate it with an OnTriggerExit2D

First we’ll write the script:

With _shopPanel created, we’ll drag it in using Unitys interface.

Great! I’m confident it’s going to work, let’s run it!

BooYah!

Tomorrow we’ll add a UI manager to manage the gem amounts, buttons, etc.

--

--