Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

Break - In Heist Multiplayer Game Blog (Week 3)

Hey everyone!

Welcome to Week 3 of development on my Heist Multiplayer Game. This week has been all about setting up the backend server and getting Unity connected to a MySQL database using PHP scripts and MAMP for local testing.

Goals for the Week

Create a working backend server environment locally with MAMP

Write PHP scripts to handle database interactions

Use Unity’s UnityWebRequest to connect to PHP endpoints

Store and retrieve user data (login, registration, etc.)

---

What I Did

1. MAMP Setup:

I installed and configured MAMP to run an Apache server and MySQL database locally. This gave me a local environment where I could test PHP scripts and database queries before moving everything online.

MAMP

To access your host and database and data

2. Database Creation:

I created a MySQL database with table for players, which includes:

id, username, hash, salt, score

Database

List of players who registered their data is automatically stored here in the database

3. PHP Scripts:

I used Sublime Text to write basic PHP scripts for:

Testing :  I made an echo at the start which indicated that it has connected to mysql database

Test php code

this is a test php code which prints hello player 500 when it gets connected to the mysql database

User Registration: Checking if the user exists, then inserting new entries

Registration php script

Login Authentication: Verifying credentials and sending back success/failure


Login php script
using various methods to check if the login php script is working or not if its not working determining the reason of failure else if it bypasses every condition like checking the password with the hash or if the username exists or not if all conditions meet then print score from the sql table

4. Unity Integration using UnityWebRequest:

In Unity, I used UnityWebRequest.Post() and UnityWebRequest.Get() to send data to my PHP scripts. I also added coroutines to handle async requests and manage responses properly.

Unity WebRequest

Creates A POST request that sends the form data (username and password) to "https://localhost/sqlconnect/register.php"


Challenges Faced

CORS Issues: At first, Unity couldn't communicate with MAMP until I configured it properly to allow cross-origin requests.

Error Handling: Debugging PHP from Unity wasn’t straightforward—had to rely on logs and echo statements for now.

The Tutorial that I followed to connect Unity with MySQL database was outdated, I had to research around the idea for the backend and the Unity WebRequest

Next Week's Goals

To assign role to each player , there are 4 players required in this game, therefore each player after logging in has to select a role, the roles cannot be repeated in the group.

This backend foundation is crucial for the game’s player persistence system, leaderboards, and role assignment for heists. Progress is steady, and I’m hyped for what's next!

If you’ve done something similar or have tips on security/hosting, I’d love to hear from you.

Until next week!

References

  1. https://www.sublimetext.com/download (Sublime Text for writing php scripts)

Viplav Patel

Support this post

Did you like this post? Tell us

Leave a comment

Log in with your itch.io account to leave a comment.