• 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 Shoopity · Oct 14, 2013 at 07:37 PM · puzzleimplementation

How to implement multiple levels of a puzzle game

What would be the best way to implement a 100 level puzzle that has five buttons? Separate objects consisting of a script that has the coding for each level, thus equaling 100 different objects and 100 different scripts? But then how to get the button press to call the correct object/script; I'm sure I can call the object by making the current level the only object that's active and doing FindObjectsWithTag(), but then how to run the script in that object since it's a different piece of script, with a different name, each time? Should I put all the code in the Update function, effectively checking the status of each button (up or down) on every frame and responding appropriately; if so, what's the performance hit on that (if any)? Do I need to create a different scene for each level? Thanks.

Comment
Add comment · Show 1
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 Shoopity · Oct 15, 2013 at 03:30 PM 0
Share

First off, this is the very first thing I've done in Unity; I'm not a total noob when it comes to program$$anonymous$$g, graphics, design and what-not, but don't let my use of ter$$anonymous$$ology fool you into thinking I actually know what I'm doing or talking about.

What I'm trying to do: Re-create a real life handheld game; it has five buttons and 100 puzzles. The real game has a light sensor and a tilt sensor. A few examples of the puzzle solutions include: Level 1, push the buttons in order from bottom to top; Level 3, push the bottom button 5 times; Level 5, bottom button 1, second button twice, third button thrice, and so on; Level X push the lower button but don't let go until the game beeps back at you, continue on to the other buttons; Level Y, the game calls out a color and you have to push that color within 0.5 seconds, repeat until the level is cleared.

Originally I had implemented the first five levels by attaching a script to the base of the gameobject with a function consisting of nested Switch statements. The first nest represented the level, the second nest being the steps required to complete that level. This function was being called whenever a button was pushed, and the script was checking which button was pushed by checking the name of button that called the function. This works just fine for the "easy" puzzles, but then I realized further puzzles will require the game to effectively prompt the player to do stuff, so certain levels need to be "active" as opposed to waiting for input from the player then responding appropriately to that action.

1 Reply

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

Answer by Shoopity · Oct 18, 2013 at 03:12 PM

OK, so I decided to make every scene a different level. This means I'll have 100 different code files for levels, and 100 different code files for buttons, but they're each relatively small.

If anyone else has any better ideas, please chime in.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

14 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

Related Questions

Pulling Puzzler 2 Answers

How to select different objects with raycast (puzzle game) 1 Answer

How to use sections of a texture? 1 Answer

Any idea on how to make objects be clicked in a certain order? (C#) 1 Answer

How do I pick up an object and place it in a spot that kind of like a missing puzzle piece? 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