In my game I am using dontDestroyOnload for some gameobjects to pass them on another level. Now the problem is that I don't want dontDestroyOnload happening when I restart the game when I die because it is producing errors.
How can I accomplish this?
Related
I'm trying to make an FPS game using unity, but I've come across a problem. When I load my main scene after pressing "RESTART", it somehow causes my game to change appearance. But when I start the game from the main scene, it looks perfectly fine.. I've tried disabling Post Processing but I believe that's not what's causing the issue, I've provided some pictures of what happens when I load the main scene through the GameOver scene and when I load it through the MainScene.
Scene loaded through the press of a button ------Main Scene (what it's supposed to look like)
Your help is much apreciated
Ok, so after quite a while of messing around with the settings I FINALLY figured it out. To get rid of uneven lighting between the scenes all you have to do is go to Window>Rendering>Lighting>Environment> (make sure "Auto Generate" is UNCHECKED) and click Generate lighting!!!
Hi I am making a fps shooter game with unity 3d and I am trying to add a in game currency system but in order to do this I need to transfer a float called coins that is on my players movement script from the level scene to the store scene in order for it to be spent and displayed on screen as a UI dose anybody know how I can do this thank you so much for your help😁
Do not store variables in scripts where they do not belong. There are multiple solutions to this problem:
Option is to create a ScriptableObject that contains variables that need to be transferred. It is instantiated in the editor by you and then assigned as an asset to your player prefab. Instead of setting a variable in the player itself, the player just sets a variable in this storage.
This storage can be anything, from a single variable (see this video for reference) to big systems like Unitys Tilemap System.
You create a component that is attached to a game object that resides in the "Dont Destroy On Load" scene. This can be done by creating a monobehaviour script and calling DontDestroyOnLoad(gameObject) in its Start method. Additionally, you can make it a singleton and access it from everywhere. For reference see this answer from the game dev stackexchange.
To be honest, I always try to go with the first one. If you want some variables to persist in a "game state" (that's what its called in Unreal), then you create it externally and reference it throughout you session. There are really a lot of situational approaches and there is no real right or wrong, but you should always keep in mind that a class should only serve a single purpose and a player script that moves the player and stores the current stats (that should live longer than the player itself) is usually a bad approach.
I have problem with ARKit in Unity. I want to place some GameObjects to plain. Now I can add endless gameobjects. But I have problem with deleting this and I do not know where write script for that. Also I need to use some parts of my Prefab like a 3d buttons and start some code(script). Can you help me please?
I have a simple Unity scene (Scene-1) and a scene with ARKit.
I can switch between the scenes using SceneManager.LoadScene("sceneName")
When I switch from Scene-1 to ARKit scene everything is fine.
But if after that I switch back to Scene-1 and once again to ARKit scene - the ARKit scene doesn't work, looks like it stuck. I see a frozen image from the camera, though all buttons work.
Why is it happening, and is there any way to load a scene with ARKit more than ones?
I would like to add multiplayer to my game. I use UMA (https://www.assetstore.unity3d.com/en/#!/content/13930) to generate a character in a character creation scene. I then use:
DontDestroyOnLoad(characterController);
To take the player to my main game scene. The UMA generated player cannot be made a prefab, cannot be duplicated or instantiated (not sure why but it doesn't work). So I then via script move the player to the spawn position where they can play the game.
I have made multiplayer games before, but in all of them I use
Network.Instantiate(playerPrefab);
to add the player to the game. The problem here is that I have no idea (nor could I find out online) how to implement multiplayer with a character ALREADY in the scene.
Any help, ideas, advice or suggestions would help me out a lot!
You can instantiate only the GameObject that has the scripts to control the player and search for the models generated by UMA which are already in the scene.
By the way, if you're using Unity 5.1 or newer Network.Instantiate is not used anymore. http://docs.unity3d.com/Manual/net-NetworkInstantiate.html