• 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 JackAshwell · Jun 18, 2020 at 01:19 PM · 2d

Wait for user input upon entering a room

So this is probably a noob question, but I wanted to know if I could modify my PortalDetection() function to wait for the user to click the enter button. I want it to happen after portalActivated is set to true but before the if statement runs. My code:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.SceneManagement;
 
 public class GameManager : MonoBehaviour {
 
     static int currentLevel = 1;
 
     public int currentLevelInspector;
 
     public List<GameObject> spawnPoints;
 
     public int level1EnemyCount;
     public int level2EnemyCount;
     public int level3EnemyCount;
     public int level4EnemyCount;
     public int level5EnemyCount;
 
     public int count;
 
     public List<GameObject> enemies;
 
     public bool portalActivated;
 
     static bool gameInProgress;
 
     public bool gameInProgressInspector;
 
     public bool enemiesGenerated;
 
     public bool gameCompleted;
 
     public SceneTransfer transfer;
 
     public MapGenerator generator;
 
     void Awake() { 
         // Function to transfer variables back to lobby scene
         Scene scene = SceneManager.GetActiveScene();
         if(scene.buildIndex == 0 & gameInProgress == true) {
             transfer.LobbyTransfer();
             gameInProgress = false;
         }
     }
 
     void Update() {
         currentLevelInspector = currentLevel;
         gameInProgressInspector = gameInProgress;
         ActivateGame();
         GamePlayer();
         PortalDetection();
     }
 
     void ActivateGame() {
         if(Input.GetButtonDown("Submit")) {
             startUp();
         }
     }
 
     void PortalDetection() {
         if(portalActivated == true) {
             if(currentLevel == 5) {
                 // Game is over
                 gameCompleted = true;
             } else {
                 // Return player to lobby
                 currentLevel ++;
                 portalActivated = false;
                 SceneManager.UnloadSceneAsync("Main Game");
                 SceneManager.LoadScene("Lobby");
             }
         }
     }
 
     void startUp() {
         gameInProgress = true;
         SceneManager.UnloadSceneAsync("Lobby");
         SceneManager.LoadScene("Main Game");
     }
 
     void GamePlayer() {
         if(gameInProgress == true & enemiesGenerated == false) {
             switch (currentLevel) {
                 case 1:
                     level1();
                     break;
                 case 2:
                     level2();
                     break;
                 case 3:
                     level3();
                     break;
                 case 4:
                     level4();
                     break;
                 case 5:
                     level5();
                     break;
             }
         }
     }
 
     IEnumerator RandomSpawner(int startEnemyCount, int endEnemyCount) {
         enemiesGenerated = true;
         yield return new WaitForSeconds(1f);
         int randomEnemy = UnityEngine.Random.Range(startEnemyCount,endEnemyCount);
         int randomLocation = UnityEngine.Random.Range(0,spawnPoints.Count);
         Instantiate(enemies[randomEnemy], spawnPoints[randomLocation].transform.position, transform.rotation);
         spawnPoints.RemoveAt(randomLocation);
     }
 
     void level1() {
         if(currentLevel == 1) {
             // Game is on level 1
             for(count = 1; count <= level1EnemyCount; count++) {
                 int startEnemyCount = 0;
                 int endEnemyCount = 1;
                 StartCoroutine(RandomSpawner(startEnemyCount, endEnemyCount));
             }
         }
     }
 
     void level2() {
         if(currentLevel == 2) {
             // Game is on level 2
             for(count = 1; count <= level2EnemyCount; count++) {
                 int startEnemyCount = 0;
                 int endEnemyCount = 2;
                 StartCoroutine(RandomSpawner(startEnemyCount, endEnemyCount));
             }
         }
     }
 
     void level3() {
         if(currentLevel == 3) {
             // Game is on level 3
             for(count = 1; count <= level3EnemyCount; count++) {
                 int startEnemyCount = 2;
                 int endEnemyCount = 3;
                 StartCoroutine(RandomSpawner(startEnemyCount, endEnemyCount));
             }
         }
     }
 
     void level4() {
         if(currentLevel == 4) {
             // Game is on level 4
             for(count = 1; count <= level4EnemyCount; count++) {
                 int startEnemyCount = 1;
                 int endEnemyCount = 3;
                 StartCoroutine(RandomSpawner(startEnemyCount, endEnemyCount));
             }
         }
     }
 
     void level5() {
         if(currentLevel == 5) {
             generator.stopPortal();
             // Game is on level 5
             for(count = 1; count <= level5EnemyCount; count++) {
                 int startEnemyCount = 0;
                 int endEnemyCount = 3;
                 StartCoroutine(RandomSpawner(startEnemyCount, endEnemyCount));
             }
         }
     }
 }

Thanks!

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

0 Replies

· Add your reply
  • Sort: 

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

346 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 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 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

How do I get collision and trigger to work? 2 Answers

Can't get object to destroy itself on collision. 0 Answers

A 2D Character Controller with Rigidbody2D.AddForce 2 Answers

How to connect a set number of nodes on a map into a grid? 0 Answers

Is there any way to draw just single dot in UI?? 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