该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
最近做作业时碰见的一个问题
需要将游戏是=时产生的一个分数变量coins导入数据库game,部分代码如下:大神帮我看看有神马问题
using UnityEngine;
using System;
using System.Data;
using System.Collections;
using System.Data.SqlClient;
public class mark : MonoBehaviour {
// Use this for initialization
void Start () {
SqlConnection sqlcon = new SqlConnection (
//"server=PC-20140516VZMW;" +
"data source=localhost;user id=sa;password=123456; initial catalog =game"); //name of database
SqlCommand cmd=new SqlCommand();
cmd.Connection = sqlcon;
cmd.CommandType = System.Data.CommandType.Text;
//sql connection
cmd.CommandText = " USE game GO EXEC insertmark @mark=coins;";//执行存储过程insertmark
SqlDataAdapter da = new SqlDataAdapter (cmd);
da.SelectCommand.Connection.Open ();
string tempip =
da.SelectCommand.ExecuteScalar ().ToString ();
da.SelectCommand.Connection.Close ();
print ("get" + tempip);
}
void CollectCoin(Collider2D coinCollider)
{
coins++;
Destroy(coinCollider.gameObject);
AudioSource.PlayClipAtPoint(coinCollectSound, transform.position);
}
void DisplayCoinsCount() //游戏界面显示分数
{
Rect coinIconRect = new Rect(10, 10, 32, 32);
GUI.DrawTexture(coinIconRect, coinIconTexture);
GUIStyle style = new GUIStyle();
style.fontSize = 30;
style.fontStyle = FontStyle.Bold;
style.normal.textColor = Color.yellow;
Rect labelRect = new Rect(coinIconRect.xMax, coinIconRect.y, 60, 32);
GUI.Label(labelRect, coins.ToString(), style);
}
// Update is called once per frame
void Update () {
}
}