数据库服务器用的是在本机的SQLServer
界面是NGUI做的两个输入框和一个按钮
按钮加载的脚本如下:
using UnityEngine;
using System.Collections;
using System.Data;
using System.Data.SqlClient;
public class Load : MonoBehaviour {
// Use this for initialization
public void OnClick() {
GameObject input_name = GameObject.Find("Inputname");
string name = input_name.GetComponent<UIInput>().value;
GameObject input_pass = GameObject.Find("Inputpass");
string pass = input_pass.GetComponent<UIInput>().value;
string connectString = "Data Source=192.168.0.122;Database=Test;uid=sa;pwd=943310";
SqlConnection con = new SqlConnection();
con.ConnectionString = connectString;
string sql = "select password from tableusers where name='" + name + "'";
SqlCommand cmd = new SqlCommand(sql, con);
con.Open();
string s = cmd.ExecuteScalar().ToString();
if (s == pass) print("登录成功");
else { print("登录失败"); }
}
}
截图