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 /
  • Help Room /
avatar image
0
Question by tillyandmisty · May 05, 2017 at 01:35 PM · c#randombeginnervariables

Beginner trying to set up random variable for game + and then some.

HIya!

For a school project I need to make a game that has three factors a kid can check. Temperature (too hot, too cold, just right), chlorine (stanky, toxic, just right) and levels (too much water, too little, just right).

I want the game to start with some random units for these. Say -1 is too hot, 1 is too cold and 0 is just right.
Then I want a script that kind of.. checks that?

So when the kid tests their water, the script essentially says:

If water is CORRECT, move onto checking next variable (chlorine), if chlorine IS NOT CORRECT, SPAWN the background image of it being toxic etc.

Does anyone know the right way to start about this? I can link my game assets I have so you can get a better idea, as well as a paper prototype so you can see where I want this game to go.

I am an ABSOLUTE beginner so I apologize!

Comment
Add comment · Show 2
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
avatar image BaldBeardedMonk · May 06, 2017 at 08:38 PM 0
Share

for the random stuff you can use the below code.. int rand = Random.Range(-1,2). // in unity the upper bound is exclusive this will give you a random integer between -1,0 & 1

and then you can use the above nested in another if code to see if it is correct then check the next parameter if not then display the pic

avatar image tillyandmisty BaldBeardedMonk · May 06, 2017 at 09:15 PM 0
Share

Hey thank you! I found out about the random range code. Could you link me to an example of what code I'd need for checking parameters and if false displaying the pic. Would it be working with bools? Or 'if' statements or am I way off (also pretty likely)?

Would I put the random range code into an empty game object named what I'm trying to check? EG chlorine? Or would I just have one big script for my whole game that goes "Check chlorine, if -1 go to this background." as well as letting a player -1 or +1 to chlorine?

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by adiict0 · May 06, 2017 at 10:02 PM

Good luck with this bud. I dont know how to do all of that but it looks like a nice proyect! Keep it up :)

Comment
Add comment · Show 1 · 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
avatar image tillyandmisty · May 06, 2017 at 10:05 PM 1
Share

Thank you!

avatar image
0

Answer by krishnalomeli · Dec 10, 2017 at 11:50 AM

ones i was having difficulties with variables i found a place where it is described in the clearest and childish way - see here - https://codeasy.net/lesson/variables_and_int_type_introduction

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

9 People are following this question.

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

Related Questions

Jump delay?? 1 Answer

Picking up an item and spawning a new one. 0 Answers

Is Random.InitState's Seed's random generated numbers change computer to computer? 0 Answers

Error CS0120-Object Reference is required to access a non-static memberUnityEngine.Rigidbody.Velocity 1 Answer

I want to change two variables with another script 0 Answers


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