对不起,如果这听起来很无聊.我正在尝试使用C#和SQL Server中的数据库在Unity上制作测验游戏.在这一部分,我试图显示最高分,所以,我做了一个代码来选择数据库中的最大值:
public bool BuscarScoreFinal1()
{
SqlDataReader dataReader = null;
if (RunQuery(string.Format("SELECT MAX (PlayerScore1) FROM ScoreQuiz1", tableScoreQuiz1), ref dataReader))
{
while (dataReader.Read())
{
id1 = dataReader.GetInt32(dataReader.GetOrdinal("ID"));
PlayerName1 = dataReader.GetString(dataReader.GetOrdinal("PlayerName1"));
PlayerScore1 = dataReader.GetInt32(dataReader.GetOrdinal("PlayerScore1"));
break;
}
}
if (dataReader != null) dataReader.Close();
return true;
}
Run Code Online (Sandbox Code Playgroud)
然后,我尝试在此脚本中的UI文本中打印数据:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class UpdateScore : MonoBehaviour
{
public GameObject Question3Display;
public Text yourText;
public bool Buscardados13;
// Use this for initialization
void Start()
{
Buscardados13 = GameObject.Find("DatabaseConnection").GetComponent<DatabaseInterface>().Connect() == true; …Run Code Online (Sandbox Code Playgroud)