How to open any specific scene when the game opens - c#

My question is that, how can I set any scene in unity as first scene (means it will open first when the game starts).
As I started making my game in unity, instead of making main menu I made LEVEL 1, and as a result when the game opens it directly starts the game by showing level 1.
So how can I set my main menu as the first scene

To further upon Retired Ninja's comment, to set a specific default scene when the game opens, you need to set the ordering of the scenes so that the one you want to start with is first, see the picture below:
The main menu screen comes first in the list of scenes, this means it will run on startup.
More details here where it has been answered on the Unity Forums:
https://answers.unity.com/questions/44953/set-first-scene.html

Related

Save current state of scene and load it

How do i save current scene state and load it later?
I'm making a game where you are building a bridge and then press start to run over it with a car and if you fail you have a restart button that reloads the scene from origin state(without anything built on it). However, i want the player to be able to press an "Edit" button that will go back to the state right before you pressed "start" so you can keep building on your bridge without having to rebuild the whole bridge over and over again. So, how do i do this?
If you don't want to code it yourself, you can use the PlayerPrefs of Unity. If you don't know how to use it look at the documentation (https://docs.unity3d.com/ScriptReference/PlayerPrefs.html) or you can also find tuto on Youtube, even some examples.

Unity hovering buildings before you place them for game

In strategy games it's common to have after you click the button to build a building, you are able to "hold" the building on the cursor, so you can place it where you want it to go. To do this, I need to have it initialize, then have it follow the users cursor with raycast.
What I need it to do:
Need to have the building initialize.
Need to have the building follow the cursor using raycast
On click, the building needs to place in a permanent spot, then destroy the old building.
The permanent building gets stored into an empty GameObject using the Transform.SetParent line. Creating a public variable for this above will allow it to be set in the game manager, rather than hard coded into a script.
In general, you will need to create code to update the position of the building to match the position of the cursor. You can get that by getting the RaycastHit point. You can do that by updating the translation of the building on every update to the current hit point.
You will likely need to keep track of the user being in some sort of building placement mode. A simple way to do that is by using a state machine.
Then, when the user clicks (or fires, or whatever you decide the appropriate mechanism is) you use that position to store the permanent position.
It's hard to give more details without know how you are tracking and storing the buildings. I'd assume it's something like an array, in which case, the second step simply involves adding the building to the array.

How to make a loading screen in Unity, that can figure out if the scene is fully loaded

I have my main menu; when the game start, it takes between 2 and 12 seconds to display the scene. During this time everything is still, and the user may think that the application is hanging or crashed.
I would like to add a simple screen (I can use a canvas and place a simple animation on it with the loading text on it), but I can't get how do you actually tell that the scene loaded.
I did try the delegate "OnLevelWasLoaded", and it is a big lie, because the code running in there is not necessarly happening when everything "pop" on screen and you can start to use the application.
I did try to add a timed function, but it is totally bogus, since I have no way to find out if the scene loaded or not, so on some machines it may be faster, and the game would run behind the loading canvas; while if I do it too short then the scene will not be fully loaded and I would end up showing again the frozen screen.
Beside OnLevelWasLoaded, is there anything else that can be used to intercept when the scene loaded?
You can use:
SceneManager.LoadSceneAsync(sceneName, LoadSceneMode.Single);
LoadSceneAsync returns AsyncOperationthat you can use in coroutine.
Here you can find more details: Doc
So you can add a loading scene that will start to load proper level asynchronously, this allow you to check when loading is completed.

How to make a XNA window close without shutting down the game

I am making a game that has a main home screen (that is a windows form) and i need some code that will just close the xna window but not the form.
I've looked everywhere but can't seem to find an answer. I figured out how to open the form, I just need to close the opened xna window so just my main menu is there and i can start another xna game.
There is an answer to your question here. Essentially, you will need to modify the opacity to hide the game window. The game will still be active.
Edit
my game continues to run in the backgound and so on my main menu i can't start another instance of that game
If you need to completely close the XNA game, the game will need to be launched from the Windows Form application. In your Windows Form application you can use:
Game1 myGame = new Game1();
myGame.Run();
to run the XNA game. Then when you use Game.Exit() (in the XNA application) to close the game, the main menu should still be open in the background.

Unity3d script seems to work in one scene but not another

I am working on a group of scenes for an opening menu (Start, Options, Exit, etc).
Right now, I have the exact same "Back" 3d Text GameObject in two of my scenes that have the same script that when clicked, uses Application.LoadLevel("Main") to return to the Main scene.
The problem is, "Back" only works in one of the scenes. It does not seem to be working in the other. They are identical (Script attached, position, name, etc.).
Any ideas what might be causing this or why this is happening?
Thanks in advance!
Fixed the problem by copying over all of the assets in the problem scene to a new scene. Now it works like a charm.

Categories