首先,這裏是我的腳本:如果這兩個值彼此相等,然後做到這一點的C#
using UnityEngine;
using System.Collections;
using Steamworks;
public class Achievements : MonoBehaviour {
public static int currentScore=0;
public static int score300 = 300;
public static int score1000 = 1000;
public static int score3600 = 3600;
public static int score18000 = 18000;
public static int score72000 = 72000;
public static int score180000 = 180000;
void Start() {
if(SteamManager.Initialized) {
string name = SteamFriends.GetPersonaName();
Steamworks.SteamUserStats.SetAchievement("NEW_ACHIEVEMENT_1_0");
Steamworks.SteamUserStats.StoreStats();
Debug.Log(name);
}
}
void Update()
{
currentScore = PlayerPrefs.GetInt("highscore");
if (currentScore == score300 && SteamManager.Initialized){
Steamworks.SteamUserStats.SetAchievement("NEW_ACHIEVEMENT_5_0");
Steamworks.SteamUserStats.StoreStats();
}
if (currentScore == score1000 && SteamManager.Initialized) {
Steamworks.SteamUserStats.SetAchievement("NEW_ACHIEVEMENT_6_0");
Steamworks.SteamUserStats.StoreStats();
}
if (currentScore == score3600 && SteamManager.Initialized) {
Steamworks.SteamUserStats.SetAchievement("NEW_ACHIEVEMENT_7_0");
Steamworks.SteamUserStats.StoreStats();
}
if (currentScore == score18000 && SteamManager.Initialized) {
Steamworks.SteamUserStats.SetAchievement("NEW_ACHIEVEMENT_8_0");
Steamworks.SteamUserStats.StoreStats();
}
}
}
正如你所看到的,我有一個持有不同數量的公共整數。我也在使用當前的steamworks.net,我試圖看看我能否與scoreXXX匹配「高分」(已經建立並正常工作)。如果發生這種情況,我希望腳本放棄成就。
我執行if(x = x)函數是否錯誤?有人可以幫忙嗎?
比較看起來不錯。你確定分數會以增量遞增,並且在'Update'時完全相等嗎?你可能想使用'> ='。在加載到調試之後,我會添加一些「currentScore」的值的記錄,並且可能在每個「if」塊的內部記錄,以驗證塊是否已輸入。 – ryachza
@GiladGreen我假設基於腳本實際上沒有「落下成就」的「我想腳本放下成就」。 – ryachza