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 ddjdewan · May 31, 2016 at 01:47 PM · c#scenelevel

How can i convert a game with multiple scene into a single scene game?

I have made a game in unity which have multiple scenes of different level in which user have to select a colored block to go the next level but i want my code to be in a single scene is there a way i can convert my multi scene game into a single scene . Code for level 1 grid base is

 public IEnumerator Start() {
         grid = new GameObject[ySize, xSize];
         float x = xStart;
         float y = yStart;
         ScreenRandom = Random.Range(0, 3);
         if (ScreenRandom == 0)
         {
             img.color = UnityEngine.Color.red;
             text.text = "Select all the Red Objects";
             yield return new WaitForSeconds(time);
             Destroy(img);
             Destroy(text);
             int check = 1;
                 for (int i = 0; i < ySize; i++)
                 {
                     for (int j = 0; j < xSize; j++)
                     {
 
                         if (check <= 1)
                         {
                             GameObject rblock = Instantiate(RedPrefabs[Random.Range(0, 1)]) as GameObject;
                             rblock.GetComponent<RectTransform>().anchoredPosition = new Vector2(x, y);
                         rblock.transform.localScale = new Vector3(1.0f, 1.0f, 1.0f) * scale;
                         rblock.transform.SetParent(canvas.transform);
                             grid[i, j] = rblock;
                             CountRed++;
                         }
                         else {
                             GameObject block = Instantiate(NonRedPrefab[Random.Range(0, 2)]) as GameObject;
                             block.GetComponent<RectTransform>().anchoredPosition = new Vector2(x, y);
                         block.transform.localScale = new Vector3(1.0f, 1.0f, 1.0f) * scale;
                         block.transform.SetParent(canvas.transform);
                             grid[i, j] = block;
                         }
                         check++;
                         x += xWidth * space;
                     }
                     y -= yHeight * space;
                     x = xStart;
                 }
 
         }
         if (ScreenRandom == 1)
         {
             img.color = UnityEngine.Color.blue;
             text.text = "Select all the Blue Objects";
             yield return new WaitForSeconds(time);
             Destroy(img);
             Destroy(text);
             int check = 1;
             for (int i = 0; i < ySize; i++)
             {
                 for (int j = 0; j < xSize; j++)
                 {
 
                     if (check <= 1)
                     {
                         GameObject rblock = Instantiate(BluePrefabs[Random.Range(0, 1)]) as GameObject;
                         rblock.GetComponent<RectTransform>().anchoredPosition = new Vector2(x, y);
                         rblock.transform.localScale = new Vector3(1.0f, 1.0f, 1.0f) * scale;
                         rblock.transform.SetParent(canvas.transform);
                         grid[i, j] = rblock;
                         CountBlue++;
                     }
                     else {
                         GameObject block = Instantiate(NonBluePrefab[Random.Range(0, 2)]) as GameObject;
                         block.GetComponent<RectTransform>().anchoredPosition = new Vector2(x, y);
                         block.transform.localScale = new Vector3(1.0f, 1.0f, 1.0f) * scale;
                         block.transform.SetParent(canvas.transform);
                         grid[i, j] = block;
                     }
                     check++;
                     x += xWidth * space;
                 }
                 y -= yHeight * space;
                 x = xStart;
             }
         }
         if (ScreenRandom == 2)
         {
             img.color = UnityEngine.Color.yellow;
             text.text = "Select all the Yellow Objects";
             yield return new WaitForSeconds(time);
             Destroy(img);
             Destroy(text);
             int check = 1;
             for (int i = 0; i < ySize; i++)
             {
                 for (int j = 0; j < xSize; j++)
                 {
 
                     if (check <= 1)
                     {
                         GameObject rblock = Instantiate(YellowPrefabs[Random.Range(0, 1)]) as GameObject;
                         rblock.GetComponent<RectTransform>().anchoredPosition = new Vector2(x, y);
                         rblock.transform.localScale = new Vector3(1.0f, 1.0f, 1.0f) * scale;
                         rblock.transform.SetParent(canvas.transform);
                         grid[i, j] = rblock;
                         CountYellow++;
                     }
                     else {
                         GameObject block = Instantiate(NonYellowPrefab[Random.Range(0, 2)]) as GameObject;
                         block.GetComponent<RectTransform>().anchoredPosition = new Vector2(x, y);
                         block.transform.localScale = new Vector3(1.0f, 1.0f, 1.0f) * scale;
                         block.transform.SetParent(canvas.transform);
                         grid[i, j] = block;
                     }
                     check++;
                     x += xWidth * space;
                 }
                 y -= yHeight * space;
                 x = xStart;
             }
         }
     } 

Code to check and Load Level 2 is:

 void Update () {
         screen = GridControl.ScreenRandom;
         if (Input.GetMouseButtonDown(0))
         {
             Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
             RaycastHit hit;
             if (screen == 0)
             {
                 if (Physics.Raycast(ray, out hit))
                 {
                     if (hit.collider.tag == "BlueBlock")
                     {
                         Destroy(hit.transform.gameObject);
                         print("GameOver");
                         Application.LoadLevel(0);
                     }
                     if (hit.collider.tag == "RedBlock")
                     {
                         RedCount++;
                         Destroy(hit.transform.gameObject);
                         Correct++;
                         Score.text = " " + Correct;
                         if (RedCount == GridControl.CountRed)
                         {
                             print("Next Level");
                             Application.LoadLevel(3);
                         }
                     }
                     if (hit.collider.tag == "YellowBlock")
                     {
                         Destroy(hit.transform.gameObject);
                         print("GameOver");
                         Application.LoadLevel(0);
                     }
                 }
             }
             if (screen == 1)
             {
                 if (Physics.Raycast(ray, out hit))
                 {
                     if (hit.collider.tag == "BlueBlock")
                     {
                         BlueCount++;
                         Destroy(hit.transform.gameObject);
                         Correct++;
                         Score.text = " " + Correct;
                         if (BlueCount == GridControl.CountBlue)
                         {
                             print("Next Level");
                             Application.LoadLevel(3);
                         }
                     }
                     if (hit.collider.tag == "RedBlock")
                     {
                         Destroy(hit.transform.gameObject);
                         print("GameOver");
                         Application.LoadLevel(0);
                     }
                     if (hit.collider.tag == "YellowBlock")
                     {
                         Destroy(hit.transform.gameObject);
                         print("GameOver");
                         Application.LoadLevel(0);
                     }
                 }
             }
             if (screen == 2)
             {
                 if (Physics.Raycast(ray, out hit))
                 {
                     if (hit.collider.tag == "BlueBlock")
                     {
                         Destroy(hit.transform.gameObject);
                         print("GameOver");
                         Application.LoadLevel(0);
                     }
                     if (hit.collider.tag == "RedBlock")
                     {
                         Destroy(hit.transform.gameObject);
                         print("Game Over");
                         Application.LoadLevel(0);
                     }
                     if (hit.collider.tag == "YellowBlock")
                     {
                         YellowCount++;
                         Destroy(hit.transform.gameObject);
                         Correct++;
                         Score.text = " " + Correct;
                         if (YellowCount == GridControl.CountYellow)
                         {
                             print("Next Level");
                             Application.LoadLevel(3);
                         }
                     }
                 }

Code for Level 2 GridBase is;

 public void Start()
     {
         grid = new GameObject[ySize, xSize];
         ScreenRandom = GridControl.ScreenRandom;
         float x = xStart;
         float y = yStart;
         if (ScreenRandom == 0)
         {
             int check = 1;
             for (int i = 0; i < ySize; i++)
             {
                 for (int j = 0; j < xSize; j++)
                 {
 
                     if (check <= 2)
                     {
                         GameObject rblock = Instantiate(RedPrefabs[Random.Range(0, 1)]) as GameObject;
                         rblock.GetComponent<RectTransform>().anchoredPosition = new Vector2(x, y);
                         rblock.transform.localScale = new Vector3(1.0f, 1.0f, 1.0f) * scale;
                         rblock.transform.SetParent(canvas.transform);
                         grid[i, j] = rblock;
                         CountRed++;
                     }
                     else {
                         GameObject block = Instantiate(NonRedPrefab[Random.Range(0, 2)]) as GameObject;
                         block.GetComponent<RectTransform>().anchoredPosition = new Vector2(x, y);
                         block.transform.localScale = new Vector3(1.0f, 1.0f, 1.0f) * scale;
                         block.transform.SetParent(canvas.transform);
                         grid[i, j] = block;
                     }
                     check++;
                     x += xWidth * space;
                 }
                 y -= yHeight * space;
                 x = xStart;
             }
 
         }
         if (ScreenRandom == 1)
         {
             int check = 1;
             for (int i = 0; i < ySize; i++)
             {
                 for (int j = 0; j < xSize; j++)
                 {
 
                     if (check <= 2)
                     {
                         GameObject rblock = Instantiate(BluePrefabs[Random.Range(0, 1)]) as GameObject;
                         rblock.GetComponent<RectTransform>().anchoredPosition = new Vector2(x, y);
                         rblock.transform.localScale = new Vector3(1.0f, 1.0f, 1.0f) * scale;
                         rblock.transform.SetParent(canvas.transform);
                         grid[i, j] = rblock;
                         CountBlue++;
                     }
                     else {
                         GameObject block = Instantiate(NonBluePrefab[Random.Range(0, 2)]) as GameObject;
                         block.GetComponent<RectTransform>().anchoredPosition = new Vector2(x, y);
                         block.transform.localScale = new Vector3(1.0f, 1.0f, 1.0f) * scale;
                         block.transform.SetParent(canvas.transform);
                         grid[i, j] = block;
                     }
                     check++;
                     x += xWidth * space;
                 }
                 y -= yHeight * space;
                 x = xStart;
             }
         }
         if (ScreenRandom == 2)
         {
 
             int check = 1;
             for (int i = 0; i < ySize; i++)
             {
                 for (int j = 0; j < xSize; j++)
                 {
 
                     if (check <= 2)
                     {
                         GameObject rblock = Instantiate(YellowPrefabs[Random.Range(0, 1)]) as GameObject;
                         rblock.GetComponent<RectTransform>().anchoredPosition = new Vector2(x, y);
                         rblock.transform.localScale = new Vector3(1.0f, 1.0f, 1.0f) * scale;
                         rblock.transform.SetParent(canvas.transform);
                         grid[i, j] = rblock;
                         CountYellow++;
                     }
                     else {
                         GameObject block = Instantiate(NonYellowPrefab[Random.Range(0, 2)]) as GameObject;
                         block.GetComponent<RectTransform>().anchoredPosition = new Vector2(x, y);
                         block.transform.localScale = new Vector3(1.0f, 1.0f, 1.0f) * scale;
                         block.transform.SetParent(canvas.transform);
                         grid[i, j] = block;
                     }
                     check++;
                     x += xWidth * space;
                 }
                 y -= yHeight * space;
                 x = xStart;
             }
         }
     }

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 Le-Pampelmuse · May 31, 2016 at 06:06 PM 1
Share

Well, this is an ordeal.

First of all, Unity Answers is not a place where people ask others to fix their scripts. However, most users will help you anyways, and that's their cup of $$anonymous$$.

  • Your question is very complicated and requires more extensive discssion. You just pasted your code and roughly explained what you want to do. That's not how we ask questions here ;) Check out this video guide, and also please read the FAQ.

  • No one wants to read 300 lines of your code, it's not neccessary to post your entire scripts when your actual question is:
    Is there a way i can convert my multi scene game into a single scene?

The bottom line is that you want to make everything happen in one scene. And that's it.

Simply don't load a new scene when your player reaches a goal. Ins$$anonymous$$d, teleport him to the next playable area (the next "level"), which is located so the player can't see it from level 1.

Or, you can disable the individual levels when the player is not on them, and when reaching a goal, enabling them.

The process is not different at all, you will most likely only have to adapt your scoring scripts, or gamelogic scripts, so that they are reset everytime the player advances to a new level.

If the player has to collect coins in level 1 and level 2, and he reaches the end of level 1, set CollectedCoins = 0;

If you want to log you players statistics throughout the levels and present it afterwards, create storage-variables in your main gamelogic script and when level 1 is done, store the CollectedCoins in level1_FinalCoins for example

It as simple as that. There is no need to overcomplicate things.

You have to ask yourself: Do I really need multiple scenes?

  • Is your game so memory-hungry, that having 2-3 level areas in one scene makes it perform bad? Do multiple scenes.

  • Is it just plain "laziness", that you have everything pre-configured in your scenes and you don't want to to those adjustements at runtime? Do a single scene. ;)

  • Are you still a beginner when it comes to changing levels and gamelogic settings like scores and player settings via code at runtime? Watch tutorials about how to make level transitions within a single scene, then apply what you have learned in your current project.

It's all about finding the problem first, then reacting to it appropriately.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Mmmpies · May 31, 2016 at 04:45 PM

I'm reading between the lines here because it isn't totally clear what you want but I think you want a different controller script for your player depending on the level.

You could have all scripts on the player but only enable the one relevant to the current level.

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 ddjdewan · May 31, 2016 at 05:18 PM 0
Share

the game involves a simple grid of objects of different color.The game stars with presenting a color then objects of different colors appear on the screen and player have to tab correct color blocks for that round. The game becomes complex with different level scene but i want the full game in a single game screen.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Cannot interact with new scene 0 Answers

How To pass from level to the next after winning, with one button ? 1 Answer

Change level after selecting a number of buttons 2 Answers

Text adventure game, how to change text in a specific way with C# 1 Answer

Restart current level after deathscreen 3 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