When to use scene or panel - unity3d

I just have a question and I don't know exactly what to type on google.
I am making a game which is always instantiating scenes now on my login process I am trying to login wrong account so there should be something that needs to pop up like an error message
Now my question is . Is there going to be a problem when I build this up because there's a tons of them or it is just normal?
But basically when i try to input the correct id and password this scenes will be deleted.

There shouldn't be a problem but this looks like an abuse of scene to me. You have too many unnecessary scenes.
Here is when you need to create or use a new scene:
1.Main Menu
This is the first scene that loads. By separating it with your game scene, you will increase loading time.
2.Game Levels
The levels in your game requires scene for each one. This makes loading them faster. You can also separate one scene into multiple ones if it's really a big scene. This also increases the speed of loading time.
You do not need scene for other things you have in your question. Those should be a UI Panels. You can create a panel by going to the GameObject ---> UI --> Panel menu. It's really easy to show/hide a panel.
For example, you have login and emergency panels:
public GameObject loginPanel;
public GameObject emergencyPanel;
to show the login panel, you disable or deactivate the emergency panel first then activate the login panel:
emergencyPanel.SetActive(false);
loginPanel.SetActive(true);
That's all you have to do.

Related

In unity how to make in-game menu?

I'm making a Unity2D mobile game but I'm stuck on making a menu. I want the in-game menu and if the player touches the screen or clicks the screen, the game will start and the menu will be have store, options but I don't know how to do it. I tried to do the same scene but this time when it goes to the next level, the menu disappears. I searched on the internet but couldn't find it. Thanks.
You should first create a UIManager script for yourself.
In this script, you must define 2D elements such as Text, Canvas, Panel and provide their functionality.
Then you can control these functions in your main manager (GameManager).
To put it simply, it takes almost a video tutorial to explain it.
Because this is not a simple code error question, man.

how to switch between loaded scenes

I am new to unity and working on a projects.
I want to work with multiple scenes.
some of my scenes are like option menu in the game.
from my main screen I want to open an options scene and when I am done I want to move back to my main scene and when I am back I want to keep the things done in main scene before the options scene opens
I can change scenes with SceneManager but it loads the screen as new as if I did nothing there
is it possible to switch between loaded scenes without loading again? I think that if it is; I can continue from the progress in the main scene
if it is not how can I continue my progress (do I have to keep all the data and when the scene starts load back from that data? )
The SceneManager class provides lots of useful ways to manage your scenes. You can find documentation here.
Using multiple scenes to separate your logic is a great approach, and using the LoadSceneMode.Additive option when loading a new scene lets you load one scene alongside another.
To achieve what you want, you'd roughly need to do the following:
Load your main menu scene.
Load your options scene additively with a call like SceneManager.LoadScene("path/to/options/scene.unity", LoadSceneMode.additive).
Pass input control to your other scene.
Unload the options scene when you are finished with it.
The main menu scene will have been loaded for the entire time, and you won't have to "remember" any values or use DontDestroyOnLoad.
An alternative option is to house all of your menu functionality in a single scene, and switch between multiple canvases. You can find information about that here.
you can create a class with values that you want to keep and put it on a gameobject
and use DontDestroyOnLoad(this.gameObject); so the object won't be removed when you load a new scene

Dynamically instantiated prefabs are invisible

Now I know that this is a common problem and there are so many mistakes that would lead to it, but I have searched and seen all the results and answers in unity forums and other websites, and I'm sure that I don't have any beginner-mistake that would lead to it.
My problem is -Like the title states- that I have a "platform" prefab and I have a script, attached to some game object in the scene, that instantiates a new platform every x seconds. Now, the scripts works and everything is fine, the platforms are instantiated and they are moving and functioning as they should, but I can't see anything from this!
I mean that I can see them in the scene view window, where everything is fine, but in the game view window nothing appears, though I can interact with the platforms, such as landing on them and so on...
check the z depth... your probably instantiating them behind your camera. a good way to check is to start the game, go to scene, and take it out of 2d, then click one of the platforms in the explorer, and check its z value
It is highly possible that they are shown "behind" your background. I was making an android app and my buttons were displayed behind the UI panel. Try to instantiate your platforms as child objects of your panel.

Is it more efficient to change scenes in Unity or to have different ui screens?

I've been working on a really simple game for iOS that has just three scenes; the start scene, game scene, and game over scene. I was running the game and analyzing performance with the profiler and I noticed that when I changed scenes, which utilized the "SceneManager.LoadLevelAsync()" function, the CPU usage was around 90%. This is only for less than a second of course, and then the CPU usage drops again and I get around 70-80 fps, but this got me wondering if it would be more efficient for a simple game like this for me to simply have several UI "screens" (basically just a group of objects that I can activate and inactivate), which is what I did with my pause screen (it is just an overlay).
Of course this could have difficulties of its own, like I would have to restart the game on the same scene but it might help me with my problem of running the mute function I've built on my music manager, which is instantiated in the start scene, from a button that is on my game scene, and I wouldn't have to use the "DontDestroyOnLoad()" function on the music manager or my score manager (which stores the score to be displayed on the game over scene). But would it be inefficient to have so many inactivated objects, or is Unity pretty good at managing things like that?
In my personal opinon, menu system should be in one scene.
Having different scenes for every menu screen will cause overhead. Even it is for few micro seconds it will affect user experience when navigating between menus frequently. This is because of loading and destroying of each UI gameObject in scene.
While menu system based in one scene requires only activating and deactivating of gameobjects instead of instantiating and destroying.
You can have one root object for menu and assign it a canvas component and then you can add different panels for each screen and assign them canvas groups to toggle them on and off smoothly.
Here is a good tutorial for creating menu system: https://www.youtube.com/watch?v=DNqTUwnpLvI
Hope this helps.
You are correct, If your game / app is small you should keep it as simple as possible, if the only difference between your scenes is just UI & your "in game" scene is not that big, you can for sure keep using the same scene and have the UI activate/deactivate.
*Inactive objects DO eat memory.

Randomly Appearing Popups In Unity3D

How can i make an image to randomly appear while in-game in Unity3D ? It will serve as my popup advertisements for my game. I want to have ads without using AdMobs or any other plugins.
Depending on how you plan to display your images. You could write a script to randomly Enable a GUI Image, then have the GUI Image become disables after a specified time is over or by a button click (like a "X" symbol or close button).
My recommendation would be some mix of the following:
Create an UI Image GameObject. Use this as the main Advertisement GameObject.
Create a script to set this gameobject active/inactive randomly throughout the game. Place this script on an object in the hierarchy that will exist throughout the game.
Create a script that will be your advertisement handler. Attach this to your UI GameObject. In this you can create some sort of structure to hold different ads or however you plan to populate the ads. Then you can customize the way the ads will be displayed. Will it be random? Will it happen sequentially? Are there different types of ads?
Create logic to disable the gameobject based on a timer or by way of a close button.
If you get around to coding and have trouble, then please feel free to ask about the coding. Also, check out the Unity Forums for questions specific to Unity.