Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • 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 Omwro · Sep 07, 2016 at 01:19 PM · loginroll a ball

is there a way how i can save the username which i use to log in to save in another script which i can use to save highscore in my database.

hi programmers and friend. first of all sorry for my bad english/grammer. i started with Unity 1 week ago and i enjoy it when im developing games. i started with the Roll A Ball tutorial. and i made my own levels. i was thinking to make a log in screen and i made it. i used MSSQL(because i have experience with it) and the log in page succeed but i also want that if u log in with a specific name that it saves the username in another script so i can use it in the levels to save scores in their own database row.

my question is: is there a way how i can save the username which i use to log in to save in another script which i can use to save highscore in my database.

here are some codes and evidence:

 using UnityEngine;
 using UnityEngine.UI;
 using System.Collections;
 using System;
 using System.Text.RegularExpressions;
 using System.Data;
 using System.Data.SqlClient;
 
 public class Login : MonoBehaviour {
 
     public GameObject username;
     public GameObject password;
     public Text errormessage;
     private string Username;
     private string Password;
     private string Form;
 
     void Start () {
         errormessage.text = "";
     }
     
     void Update () {
         Username = username.GetComponent<InputField>().text;
         Password = password.GetComponent<InputField>().text;
 
         if (Input.GetKeyDown(KeyCode.Tab))
         {
             if(username.GetComponent<InputField>().isFocused)
             {
                 password.GetComponent<InputField>().Select();
             }
         }
 
         if (username.GetComponent<InputField>().text != "" &&
             password.GetComponent<InputField>().text != "" &&
             Input.GetKeyDown(KeyCode.Return))
         {
             LoginButton();
         }
     }
 
     public void LoginButton()
     {
         SqlConnection con = new SqlConnection("Data Source=(local);Initial Catalog=Roll A Ball;Integrated Security=True");
         bool login = false;
         con.Open();
         string sql = "SELECT * FROM Login WHERE Username='" + Username + "' and Password='" + Password + "'";
         SqlCommand cmd = new SqlCommand(sql, con);
         SqlDataReader dr = cmd.ExecuteReader();
         while (dr.Read())
         {
             login = true;
         }
         dr.Close();
         con.Close();
         if (login == true)
         {
             Application.LoadLevel(1);
         }
         else
         {
             errormessage.text = "Failed To Log In";
         }
     }
 }

Screenshots from the MSSQL DB table: http://prntscr.com/cf7ess http://prntscr.com/cf7f1d

i hope i was clear enough and if u want more codes or even my project. write a comment. thank you in advance.

EDIT: i think i wasn't clear enough. i have 2 databases: Login and Highscore. i also have a Login page. in the login page when i try to login, i use a Username and a Password. the Username is saved in the script Login. but after the Login i need to know with which username i logged in so i want to save the Username which i used in the Login page in another script so i can use that Username to save my highscore.

In General: is there a way how to acces or save a Variable in another script?

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Omwro · Sep 08, 2016 at 11:20 AM

NVM. i found the solution. i did need to change "private string Username" to "public static string Username" and write in another script: string UsernameID = Login.Username;

Comment
Add comment · Share
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

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.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

.net sockets login server 0 Answers

how unity3d get authentication from web 0 Answers

Advice on transferring a unity project to android studio. 0 Answers

in the roll a ball game tutorial i am unable to move the ball and it is sinking below the plane how to rectify it 1 Answer

Camera Collision for Rolling Ball 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