无法将类型`Steamworks.CSteamID'隐式转换为`float'

时间:2017-09-28 05:44:04

标签: c# unity3d steamworks-api

我目前正在使用带有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");
        }
    }
}

1 个答案:

答案 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");
        }
    }
}