First Android Game - Part 14 - Syncing Levels Aug 10, 2023
This is part 14 of making my first Android Game. If you missed part13, you can find it here I want to have a way to sync the background images and level increase across the network. I only want the master client to send this. In ScoreManager.cs, I added back the AddLevel() function The AddLevel() function would call the RPC function called AddLevelRPC that increases the level text and invokes the event LevelIncreaseEvent. This event has the background change subscribed to it To test if this works, in Update(), when I press "A" I would call the AddLevel() function Since the photonview is needed and the ScoreManager.cs is attached to the ScoreBoard prefab, the prefab must be put into the resources folder The scoreboard prefab has PhotonView component attached to it To change the background, I am looping through an array. To make sure I don't get index out of range, I would do a check to see if spriteIndex has passed the sprite array count Using the "A" key to test. The background changes, level increases, and it gets synced across the network Now I need to choose when to incrase a level. Level 2 occurs if 5 potato enemies gets destroyed. In ScoreManager, I created a int property called PotatoEnemyDestroyed that checks if 5 potato enemies get destroyed, then call AddLevel() The Enemy getting destroyed in EnemyBase.cs was modified so that there is a virtual EnemyDestroyed that will call EnemyDestroyedRPC function. The RPC function logic is the same as before where it spawns the explosion The Enemy.cs that inherits from EnemyBase.cs will override EnemyDestroyed, in here I will set the property PotatoEnemyDestroyed to 1, so that the number of enemy destroyed will increase by 1 I uncommented Level2() and Level3() in EnemyCannonSpawnInstance.cs Level2Routine() and Level3Routine() in EnemyCannonSpawnInstance.cs is modified so that I check if the anywhere in the list is null, since we destroy the enemy instead of disabling the enemy which was done when this game was only 1 player Check out the youtube video button above to see the results! See the next blog part 15 here
Recent blogs See all blogs