Hi! I’m new to Unity, but I recently developed and completed a cooking game for a game jam. Here’s a quick photo:
TL;DR: How would you deal with multiple ovens in a cooking game? How would you pass on the flavor variable?
The game is Kentucky Fried Cakes, where a chicken chef prepares fried cakes. In this cooking game, I wanted the player to be able to cook two different cakes in the ovens - like cook a vanilla cake and a chocolate cake at the same time in different ovens. The ovens had a “CookCake” script, where the flavor of the cake was a string. I later used the flavor variable several other times in the program (like in the frier). I couldn’t figure out how to use the flavors from two different ovens though. The ways I thought to accomplished this didn’t work.
Firstly, I thought about making the flavor a static variable, but that didn’t make sense. I wanted to have two separate flavors for the two different ovens and assigning a static variable would have given both ovens one shared flavor.
Secondly, I thought about making the flavor an instance variable, but that didn’t work out either. Then, I would have had to to get the friers to FindObjectOfType() and then get the instance variable flavor from there. The problem is, I didn’t know how FindObjectOfType was going to work – was it going to find the left oven? The right oven? So it could give me chocolate flavor, when really I just baked a vanilla cake in the oven.
Another problem with the instance variable strategy – I was going to make a public GameObject of the oven at the top of the frier script, and then drag one of my ovens into the slot in Unity. Then I would getComponent to get the CookCake script and then get the flavor. However, the problem with is that only one of my ovens would correlate to each frier. Like if I made the left oven give its flavor to the left frier, and the right oven to the right frier. But there’s a problem with this: what if I made a cake in the right oven, and then tried to use the left frier, and the left frier didn’t have a flavor because nothing was made in the left oven? Wouldn’t that confuse the player?
So here’s my question - how would you find the flavor? Any thoughts on my logic, any alternative ideas? The game is already published and completed, but I would highly appreciate some feedback / advice / discussion on how to approach this problem so I can improve my programming. Thanks!!