我目前正在使用带有Unity3d和C#的Steamworks.net。我想要做的是获取Steam用户ID,在这种情况下是我自己的ID,然后执行一个函数。
这是我到目前为止所做的:
private static float berdyevID = 76561198040013516;
private static float steamID;
void Start() {
if(SteamManager.Initialized) {
string name = SteamFriends.GetPersonaName();
// get steam user id
steamID = Steamworks.SteamUser.GetSteamID();
// see if it matches
if (berdyevID == steamID) {
Debug.Log ("Steam ID did match");
} else {
Debug.Log ("Steam ID did not match");
}
}
}
我收到Unity的错误声明:
无法隐式转换类型Steamworks.CSteamID' to
float'。存在显式转换(您是否错过了演员?)
让我感到困惑。我尝试在谷歌上进行研究以找到可能的修复,但找不到任何东西。有人可以帮忙吗?
修改:
我尝试了这个,但它不起作用:
private static ulong berdyevID = 76561198040013516;
private static ulong steamID;
void Start() {
if(SteamManager.Initialized) {
string name = SteamFriends.GetPersonaName();
// get steam user id
steamID = Steamworks.SteamUser.GetSteamID();
// see if it matches
if (berdyevID == steamID) {
Debug.Log ("Steam ID did match");
} else {
Debug.Log ("Steam ID did not match");
}
}
}
答案 0 :(得分:5)
您的GetSteamID()
会返回Steamworks.CSteamID
类型的对象,该对象无法分配给steamID
类型的变量float
。
ulong
结构中有一个名为m_SteamID
变量的CSteamID
变量。这就是id所在的位置。
private static ulong berdyevID = 76561198040013516;
private static ulong steamID;
void Start() {
if(SteamManager.Initialized) {
string name = SteamFriends.GetPersonaName();
// get steam user id
steamID = Steamworks.SteamUser.GetSteamID().m_SteamID;
// see if it matches
if (berdyevID == steamID) {
Debug.Log ("Steam ID did match");
} else {
Debug.Log ("Steam ID did not match");
}
}
}