- Home /
How to change from login scene to character costum scene ?
Ok what im trying to say is that ive a login page where it uses database , and a function if (w.text == "login-SUCCESS") { Application.LoadLevel(1); but as the new scene opens up i want it to show welcome user that has just logged in , with database please help thanks !
This parameter takes a string, that is the scene name, you can have multiple scene's in your project, on your login scene call it, "SceneLogin" and when the login is authenticated then use the above to load "Scene$$anonymous$$ain" or something, on Scene$$anonymous$$ain you can make welcome UI.
If you want to keep some data between the scenes you could also use Application.LoadLevelAdditive to keep the same scene and just append to it or Object.DontDestroyOnLoad to keep an object alive between scene transitions.
Answer by Agemennon · Nov 28, 2013 at 12:01 AM
I might be making assumptions here, but it seems your issue is that you want to carry information from one scene into the next.
You probably want to look into Object.DontDestroyOnLoad
Essentially you want to call this on a GameObject with a script which can tell your welcome panel to say things after your new scene loads.
Answer by diegzumillo · Nov 28, 2013 at 12:03 AM
I don't know what is the best approach here, but you can have the username stored in the playerprefs, so it's accessible on all scenes. You can also store this and whatever other information you find relevant in a gameobject that isn't destroyed on loading a new level. You do that by using DontDestroyOnLoad (transform.gameObject);
Answer by mbivol10 · Nov 28, 2013 at 11:04 AM
thanks i do get the part of saving the object but i need to know how to get the name out of the database on load , a script that will load the name to the player prefab from the database after login thanks :) of course im researching but the scripts that are on the internet that i have researched so far do not load to the player prefab from the actual database if anyone knows please leave the script here thanks :)
When you initially asked your question you implied that you already had a database connection script.
Since its is unlikely that you'll find someone here that will just outright write a script for you like that, you're probably want to look into some tutorials that involve using whatever database you're trying to use with C# prior to interfacing that with Unity.
It seemed implied. (And you just made a comment using the answer system :P)
Answer by anderas · Nov 28, 2013 at 01:04 PM
If I understand your question correctly, you log the user in on the main menu scene, load another scene and want to access the data from the database, right? I have a similar situation in my application.
I solved it this way:
Create a GameObject ("DataContainer" in the following points)
Attach a script that calls DontDestroyOnLoad(gameObject) to this object
Attach another script that basically only consists of public fields for the user data to the DataContainer object
After you logged in the user, put all relevant data into the script from the last point.
Load the next scene using Application.LoadLevel
Get the data from the DataContainer object in a script from the new scene/level and draw your welcome screen
Attach another script that basically only consists of public fields for the user data to the DataContainer object After you logged in the user, put all relevant data into the script from the last point. well whats what im stuck on the script i use is working good you can find it here http://lunerisonline.host56.com/ the reason i put login and register in css is for youto be able to read the files online because in php will just not be possible to read but anyway: "it but the consists of public fields and put all data with field" , that is really what i don't get its just don't understand , but i will try the part where the data is saved to the game object that part is the question , how do i do save that data , first i have a database called account and it has a table that consists of : id,user,name,cash,level,pass and i would like to take the data and put into the object that does not get destroyed yes i got the script of not to destroy and im going to put it into an empty game object now but please help me with the part where it takes from the database and puts into the game object into the new level(scene) thanks :)
thanks anyway i think i found what i was really looking for Here :) step by step of what i was looking for what ive got to do next is a garage with equip and buy which i already have but not the items , especially loaded from the database ill have to get used to database coding thats what i have so far of what my next thing is going to do look like :) thanks :)
![alt text][2]
Answer by palalopea · Dec 07, 2017 at 07:18 AM
can someone share the script when we use DontDestroyOnLoad?