Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by elikaj · Mar 25, 2020 at 01:16 AM · variablescopeadvicecomplete

How to approach individual variables for cooking game

Hi! I'm new to Unity, but I recently developed and completed a cooking game for a game jam. Here's a quick photo: alt text

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.


  1. 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.

  2. 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.

  3. 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!! :D

screen-shot-2020-03-22-at-80445-pm.png (34.9 kB)
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by UnityToMakeMoney · Mar 25, 2020 at 02:25 AM

Why not make a static array of size ovens which we will call flavors. Each oven would correlate to a number that would also be static so when a new oven is instantiated it is increased by 1. If we want to store a flavor we would just say flavors[oven's number] = flavor; Now when you need the flavor based on the oven you are using you just call flavors[oven's number]

f.y.i - I am really tired and it was one too many words to read, so I may be suggesting a bad idea.

I think that is similar to your first idea, but instead, it is an array.

Hope This Helps :D

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

130 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Can I declare a variable inside a function which has instance scope? 1 Answer

Cannot access AudioSource from within function 0 Answers

Scripts accessing one another (JS) 0 Answers

Scope issues when initializing variables 2 Answers

Accessing variable from another class gives initial value 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges