hey, since I’m pretty new to unity and scripting in general I still struggle to come up with ideas of my own. I’m looking for a way to instantiate several grids (like in an autobattler, one grid for one player) like we constructed in this course. Unfortunately, it seems like I can’t find a solution, since we used a static within this levelGrid. Any ideas for solutions are welcome this course already helped me immensely!
Hmm I’m not sure I understand what you’re trying to build, an auto battler like Dota 2 Auto Chess?
I’ve never played it myself but it looks like both the player and the enemy play on the same Grid.
If you really need to create multiple GridSystems, then depending on the implementation you might want to keep just one LevelGrid that manages all GridSystems. Or really implement multiple LevelGrid’s, one for the player and one for the enemies, etc.
The principle would be like Dota Auto Chess or TFT.
Basically, between the battlerounds each player has their own Grid to place units on. For each battleround the units of each player would need to join each other (lets say Team1 joins Team2 to fight on Team2’s grid). There would still be the need auf multiple grids, so that each Player can place their own units accordingly on their own grid.
Another solution would be that the enemy Team would be somewhat duplicated on another grid without the changing of grids.
As you said, it’s probably for the best to keep one LevelGrid for all Gridsystems, since they all do the same actions. How would I instantiate multiple Gridsystems on different positions within one scene?
Just by adding more instances to the Awake() of the LevelGrid script?
It sounds like you are moving into the realm of multiplayer and that is a course on its own.
But even in multiplayer, there is still only one grid - in some way. The player see that one grid, and only his/her own units. This grid would generally also exist on the server - but it’s the same grid - and once the battle starts, the server will make both players’ units visible to each other and simulate the battle
As already answered, the best solution to this particular problem is probably having a single large grid system or just having a level grid with multiple grid systems, but there is also another option.
The problem you have is that you want multiple grid systems and so you can’t use the static reference to the LevelGrid (it can’t be a singleton).
This is perfectly fine, you can remove the static methods and have each Unit (or any other classes) reference its player’s LevelGrid.
The last problem that you need to solve is how to get the reference to the right LevelGrid into the Unit object. This would be probably best done by some “Player” object that is responsible for creating the Unit. Each Player would have a reference to its own Grid and pass that reference to the Unit after it is created.
You could present each player with a small microgrid of starting locations… say your squad size is 5, you could have 10 locations that correspond to locations on the map. Make the four edges of the map identical, with 10 slots on each edge…
I’d probably use a class placeholder for these that would be put on the starting locations:
public class StartingLocation: Monobehaviour
{
[field: SerializeField] public int Team {get; private set;}
[field: SerializeField] public int Slot {get; private set;}
}
At the start of the game, each team would have their locations transposed to the corresponding StartingLocation. At that point, they would all be on the same grid, which is where they would need to be for the duration of the round.