Hello Unity fans, and welcome back to my hex map game development series. At this point in the series we’ve got the start of our UI in place, and some reasonable graphics in terms of woodcutters, stonemasons and farmers. Feel free to pause this video and take a look at some of the earlier ones if you’d like to see how we got to this point. Today we’ll be linking everything up with the game mechanics so that we can start keeping track of resources, actually pay to get our buildings constructed and properly attribute the advantages received from these buildings. This will shed some light on the process of getting a gameplay idea to actual implementation.
Part0 (Introduction): • [Unity3D Hex Map Game Dev] 0: Introduction...
Part1 (Hexes to Water): • [Unity3D Hex Map Game Dev] 1: Hexes to Water
Part2 (Features and Textures): • [Unity3D Hex Map Game Dev] 2: Features, Te...
Part3 (Units, Visibility): • [Unity3D Hex Map Game Dev] 3: Units, Pathf...
Part4 (Random Maps): • [Unity3D Hex Map Game Dev] 4: Creating Ran...
Part5 (Post Processing): • [Unity3D Hex Map Game Dev] 5: Post Process...
Part6 (Resource Gathering): • [Unity3D Hex Map Game Dev] 6: Automated Re...
Part7 (Spinning Selector): • [Unity3D Hex Map Game Dev] 7: Spinning Obj...
Part8 (Preparing for Resources): • [Unity3D Hex Map Game Dev] 8: Preparing fo...
Part9(How Much Wood?): • [Unity3D Hex Map Game Dev] 9: How Much Woo...
Part10(Dynamic Trees): • [Unity3D Hex Map Game Dev] 10: Dynamic Trees
Part11(Meet The Meeples): • [Unity3D Hex Map Game Dev] 11: Meet The Me...
Part12(Harvesting Wood): • [Unity3D Hex Map Game Dev] 12: Harvesting ...
Part13(Harvesting Stone): • [Unity3D Hex Map Game Dev] 13: Harvesting ...
Part14(Walking Around Wallls): • [Unity3D Hex Map Game Dev] 14: Stop Walkin...
Part15(Multiple Unit Types): • [Unity3D Hex Map Game Dev] 15: Preparing f...
Part16(Manipulate Terrain): • [Unity3D Hex Map Game Dev] 16: Manipulate ...
Part17(ResourceBuilding Upgrades): • [Unity3D Hex Map Game Dev] 17: Resource Bu...
Part18(Camera Fly-through): • [Unity3D Hex Map Game Dev] 18: Camera Fly ...
Part19(Animated UI): • [Unity3D Hex Map Game Dev] 19: Animated Us...
Part20(Automated Farming): • [Unity3D Hex Map Game Dev] 20: Automated R...
Part21(UI Anchors, Buttons, ToolTip): • [Unity3D Hex Map Game Dev] 21: UI Anchors,...
A large part of what we’re covering today is about how we represent our game information behind the scenes. A game needs some constraints, and your decisions need to have an impact. We start off with creating a data structure or class for the information we need to store for our city itself, similar to what we did for Resources.
In order to create a city behind the scenes, we simply allocate memory for the city and call the constructor of the class, specifying values for each variable in each sub-class. This is the same process we used to define resource and gatherer types before. We create an array to cater for more than one city later on, but only populate one for now.
Next, we define a general building specification class. We specify how much of each resource the building costs, how much of each resource it produces once built, and how much of each type of capacity it adds for the city. We also implement a method to tell us if the city can currently afford to build that building.
Now, whenever we build one of the three buildings as before, we just need to slot in the behind-the-scenes method as well to actually affect the build. At that point in the code we already know which type of building is being built, so adding these four lines covers all our building types in one go. We can do this because we made the building specification so general, so it caters for all the possible buildings.
If we now build these buildings on the map, you will see how the resources, production and capacity change as a result. But I haven’t shown you how we get these text labels to update. It’s very straightforward. In the UI script, we specify a TextMeshPro element for each of the UI labels. Then, whenever an action has been taken that impacts on these, we set them equal to the corresponding values in the city information class.
So, whenever we take an action that updates the city’s information, the labels get updated as well. But how do we stop ourselves from plonking down more and more buildings? We’ve already introduced the method that tests whether a building can be afforded. All we do now is test for it when we try to build a building. If we can afford it, we continue building and subtracting the resources from our stockpiles. If not, we stop the intended building and display a message to inform the player of the situation. Since we may want to have more than one message visible on the screen for a while to allow the player to read them all should a few come in close together, I’ve built a very basic message displaying system that moves older messages up when a new message is created.
And that’s it for today. Our graphics and UI have now been properly linked to our gameplay and mechanics, so the player is limited by the constraints on resources, and his actions are actually impacting the game in specific ways. Since we’ve created very generic classes and methods, we can now quite easily expand on this by including more building types, specifically ones that are not based on gathering resources.
Информация по комментариям в разработке