我正在尝试从我的GameController.cs脚本访问协程,协程位于我的DatabaseManager.cs脚本中。我正在尝试像这样访问协程:
DatabaseManager d1 = new DatabaseManager();
d1.uploadData();
这给了我一个空引用异常。我知道在我尝试访问的协程中一切正常,因为这些脚本与我制作的另一个项目完全相同,唯一的区别是在另一个项目中我通过一个运行良好的动画事件调用协程,但是试图通过这个项目中的代码调用它给了我这个问题。
数据库管理器脚本附加到 Player 游戏对象
数据库管理器脚本
using UnityEngine;
using UnityEngine.Networking;
using System.Collections;
using UnityEngine.UI;
using CompanionLibrary; //include my library to utilise its functions
//use neccessary libraries.
//This class handles sending game data to the database.
public class DatabaseManager : MonoBehaviour
{
//declare variables to hold data values.
static string username;
string password;
int score =0;
int kills=0; //initialise variables to 0
int bulletsFired=0;
int bulletsHit=0;
int bulletsMissed=0;
int timePlayed = 0;
int scorePerMin=0;
StatGeneration companion = new StatGeneration();
//On awake function to check if sign in or logged in booleans are set.
public void Awake()
{
if (ButtonManagers.signedUp == true) //if signedUp boolean is true....
{
username = ButtonManagers.signUpUsername; //assign the username to equal the signUpUsername value.
password = ButtonManagers.signUpPassword; //assign the password to equal the signUpPassword value.
Debug.Log("Username: " + username);
Debug.Log("Password: " + password);
}
//if loggedIn boolean is true....
if (ButtonManagers.loggedIn == true)
{
username = ButtonManagers.loginUsername;//assign the username to equal the loggedInUsername value.
password = ButtonManagers.loginPassword;//assign the password to equal the loggedInPassword value.
}
}
阿波罗的战车
相关分类