itch.io is community of indie game creators and players

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.

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

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

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

Login Authentication: Verifying credentials and sending back success/failure


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.

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

Viplav Patel

Leave a comment