IndieSquare Official Blog

News, updates and opinions about IndieSquare, Bitcoin, Counterparty, and the token economy.

Follow publication

Develop a Lightning Game with Unity BTCPay SDK — Part 2(set up Unity Project)

--

For this tutorial, we are going to use a game project asset from Unity Asset Store, called “Survival Shooter” and this article is inspired by this Unity’s live tutorial “Creating an In-Game Shop”, where it adds an In-Game Shop UI to Survival Shooter game.

So, Our base project is “Survival Shooter” project, and with this Unity tutorial for In-Game Store, you create in-Game Store UI. But, this Unity tutorial itself is 1 hour long, and if you actually do this tutorial, It would take 2 hours or more, depending on your skill level.

So, We have prepared the version of Survival Shooter which comes with In-game shop UI already, so that you only need to integrate it with the Unity BTCPay SDK. Sounds good?

Install testnet Lightning wallet for testing the lightning game

If your phone is android, Download eclair testnet wallet. And get some fund from faucet. https://faucet.lightning.community/

If your phone is iphone, Check this link for ios lightning Wallet, which does not require a backend lightning daemon. SwiftLightning may work.

Download In-Game Shop version of Survival Shooter

Now, let’s get the ball rolling!

<Click to download Unity Project>

Download the zipped file containing the initial Unity project and Open from the latest Unity. Check if it works by clicking the play button. It should work both on Windows and on MacOS.
How to test this initial Unity project is shown the video below.

https://youtu.be/gcWDq7r-ecs

Once you have open the project, download the Unity BTCpay SDK package from our Github release page. It contains the SDK’s dll and dependencies and C# sample codes, sample game objects and etc.
Check how to import it by the video below.

https://youtu.be/siKAjfCL80A

Now, it’s coding time! Here is the steps we will take on Unity and Code editor. (In this video, I use Visual Studio 2017 as Csharp code editor. You may use MonoDevelop.)

  1. Create LightningManager as empty Game Object and put csharp code on it.
  2. Add Canvas and Panel for lightning QR code image, which will popup when weapon button on Shop UI is clicked.
  3. Add close button to cancel Lightning payment
  4. On BTCPay server, create a pairing code (please check the post Part1)and set it on inspector of LightningManager

Create LightningManager

We are going to create an empty Game object where we put the most of logic. We call it lightningManager, which has requirements below.

  1. Instantiate the object of BTCPayClient class from SDK, which is main class
  2. Get Lightning BOLT invoice string using SDK and from BTCPay server
  3. Generate QR code image out of the invoice string using SDK
  4. Show QR code for the player to scan from LN wallet
  5. Subscribe to the invoice payment event and pass callback
  6. Callback to handle Invoice passed when payment is done

https://youtu.be/XW8FKd_LZ3w

Check this video which covers above.

Once the LightningManger code and QR code UI are set. Almost done.

Last tutorial video is below. In this video, wrap up by setting Gameobject references and test the game.

https://youtu.be/qTuL87D-6sk

Hope you have successfully run the game and buy a weapon with the lightning wallet.

Please comment below if you have faced any issue or suggestion for improvement.

Sign up to discover human stories that deepen your understanding of the world.

--

--

Published in IndieSquare Official Blog

News, updates and opinions about IndieSquare, Bitcoin, Counterparty, and the token economy.

Written by Masashi Nakane

Engineer on Microservices, Bitcoin, Security

Responses (1)

Write a response