我想在螢屏上顯示玩家在玩游戲后的這么長時間內實作了他們的目標。但是當我顯示 Time.time 時,它??會不斷變化。我想記錄事件發生時經過的時間并將其顯示為固定數字字串。
uj5u.com熱心網友回復:
當玩家達到目標時,將 Time.time 存盤在類變數中(即在類內部宣告但在任何函式之外)。然后顯示該變數而不是 Time.time。
uj5u.com熱心網友回復:
你想記錄比賽的結果嗎?如果是這樣,您可以嘗試在場景中創建一個新的畫布,并在畫布中創建一個新影像作為背景影像。您可以通過 Inspector 界面設定影像的相關屬性。

設定好背景后,在場景中添加一個Button,根據個人需要設定Button在按下、抬起、禁用時的不同狀態。并在canvas下添加一個C#腳本檔案——StartMenuController

啟動界面代碼為:
public void OnStartGameButtonClick()
{
//When the button is pressed, jump to the game interface
SceneManager.LoadScene(1);
//The parameter in the LoadScene() function can be the number of interfaces in builtsettings or the scene name
}
最終介面代碼為:
public void OnExitButtonClick()
{
Application.Quit();
}
將畫布中的每個功能指向相應按鈕的onClick。希望對您有所幫助,謝謝
uj5u.com熱心網友回復:
訪問播放器生成的資料,然后將其讀出。這個想法對你有幫助嗎?在 Unity 中創建一個新的 C# 代碼,將以下代碼復制到其中并將其掛載到一個空物件上。下面的代碼分為兩種方法:SaveGame(保存資料)和LodeGame(讀取資料)。可以在游戲中創建兩個Button,分別創建點擊事件。
public Inventory myInventory;//Data to be saved
public Item HpMedicine;//Data to be saved
public void SaveGame() //Save game method
{
Debug.Log(Application.persistentDataPath);
if (!Directory.Exists(Application.persistentDataPath "/game_SaveGame"))
{
Directory.CreateDirectory(Application.persistentDataPath "/game_SaveGame");
}
BinaryFormatter formatter = new BinaryFormatter();//Binary conversion
FileStream file = File.Create(Application.persistentDataPath "/game_SaveGame/Inventory.txt");
var json0 = JsonUtility.ToJson(myInventory);//Data Json conversion to be saved
var json1 = JsonUtility.ToJson(HpMedicine);//Data Json conversion to be saved
var json2 = JsonUtility.ToJson(MpMedicine);//Data Json conversion to be saved
formatter.Serialize(file, json0);//Saved data
formatter.Serialize(file, json1);//Saved data
formatter.Serialize(file, json2);//Saved data
file.Close();
}
public void LoadGame()//Read the game method
{
BinaryFormatter bf = new BinaryFormatter();
if (File.Exists(Application.persistentDataPath "/game_SaveGame/Inventory.txt"))
{
FileStream file = File.Open(Application.persistentDataPath "/game_SaveGame/Inventory.txt", FileMode.Open);
JsonUtility.FromJsonOverwrite((string)bf.Deserialize(file), myInventory);//Saved data
JsonUtility.FromJsonOverwrite((string)bf.Deserialize(file), HpMedicine);//Saved data
JsonUtility.FromJsonOverwrite((string)bf.Deserialize(file), MpMedicine);//Saved data
file.Close();
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/466307.html
