小编Pro*_*mer的帖子

无法将类型“ Steamworks.CSteamID”隐式转换为“ float”

我目前正在将Steamworks.net与Unity3d和C#结合使用。我要做的是获取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");
        }


    }

}
Run Code Online (Sandbox Code Playgroud)

我从Unity收到一个错误,指出:

无法隐式转换类型Steamworks.CSteamID' tofloat'。存在显式转换(您是否缺少演员表?)

这让我感到困惑。我尝试在Google上进行研究,以找到可能的解决方法,但找不到任何东西。有人可以帮忙吗?

编辑

我试过了,但是没有用:

private static ulong berdyevID = 76561198040013516;
private static ulong steamID;

void Start() {

    if(SteamManager.Initialized) { …
Run Code Online (Sandbox Code Playgroud)

c# unity-game-engine steamworks-api

1
推荐指数
1
解决办法
722
查看次数

在运行时将网格转换为stl/obj/fbx

我正在寻找一种在运行时将网格导出为stl/obj/fbx格式并将其保存在Android手机的本地文件中的方法.

我该怎么做呢?如果存在,我愿意使用插件(免费/付费).

c# android mesh unity-game-engine fbx

1
推荐指数
1
解决办法
3985
查看次数

如何在 Unity 中使用 WASD 移动 2D 对象

我下面的代码仅适用于水平移动。垂直运动不应该也起作用吗?我刚刚开始学习基本的 2D Unity 编程:

public class Player : MonoBehaviour {

    //These fields will be exposed to Unity so the dev can set the parameters there
    [SerializeField] private float speed = 1f;
    [SerializeField] private float upY;
    [SerializeField] private float downY;
    [SerializeField] private float leftX;
    [SerializeField] private float rightX;

    private Transform _transformY;
    private Transform _transformX;
    private Vector2 _currentPosY;
    private Vector2 _currentPosX;

    // Use this for initialization
    void Start () {
        _transformY = gameObject.GetComponent<Transform> ();
        _currentPosY = _transformY.position;        

        _transformX = gameObject.GetComponent<Transform> ();
        _currentPosX …
Run Code Online (Sandbox Code Playgroud)

c# monodevelop unity-game-engine unity3d-2dtools

1
推荐指数
1
解决办法
3万
查看次数

如何在Unity3D中检查智能手机是否有陀螺仪?

我正在使用Google Cardboard SDK。在旧版本的Google Cardboard SDK 中,它包含一个名为AndroidManifest.xml的文件

<uses-feature android:name="android.hardware.sensor.gyroscope" android:required="true"/>
Run Code Online (Sandbox Code Playgroud)

因此,解决方案可能是将该文件简单地添加回我的项目。

但是我不喜欢它,因为如果我这样做,如果设备没有陀螺仪,该应用程序就会隐藏在 Google Play 中,这让用户感到困惑,因为他们倾向于在 Google Play 中搜索它。

那么,我如何从代码中检查设备是否有陀螺仪以向用户显示一条消息,例如:这款智能手机确实有陀螺仪。请尝试使用其他智能手机。

c# unity-game-engine google-cardboard google-vr google-vr-sdk

1
推荐指数
1
解决办法
2826
查看次数

循环通过Transform的子时出错

我想遍历转换的所有子项,但我收到错误.

这是我想让所有孩子来自的变量:

public Transform parentToSearch;
Run Code Online (Sandbox Code Playgroud)

然后我在编辑器中将一个Transform对象从Hierarchy拖到了脚本中parentToSearch.

然后在脚本中我想循环遍历此Transform的所有子项:

private void OnGUI()
    {
        if (hasDescription == true && clickForDescription == true)
        {
            foreach (GameObject child in parentToSearch)
            {
                if (child.GetComponent<ItemInformation>() != null)
                {
                    ItemInformation iteminformation = child.GetComponent<ItemInformation>();
                    if (child.name == objectHit)
                    {
                        var centeredStyle = GUI.skin.GetStyle("Label");
                        centeredStyle.alignment = TextAnchor.UpperCenter;
                        GUI.Label(new Rect(Screen.width / 2 - 50, Screen.height / 2 - 25, 100, 50), iteminformation.description, centeredStyle);
                    }
                }
            }
        }
    }
Run Code Online (Sandbox Code Playgroud)

例外是在线:

foreach (GameObject child in parentToSearch)
Run Code Online (Sandbox Code Playgroud)

这是错误:

InvalidCastException:无法从源类型转换为目标类型

c# unity-game-engine unity5

1
推荐指数
1
解决办法
54
查看次数

附着在GameObject上的粒子系统为粉红色

我正在研究统一粒子系统。

我创建了一个新项目,然后创建了一个空对象,然后向其中添加了粒子系统。由于某种原因,它无法正常工作,您可以看到附件中的图像,以查看发生了什么...

在此处输入图片说明

c# 3d game-development unity-game-engine

1
推荐指数
2
解决办法
1580
查看次数

在 Android 上播放大视频无延迟

我正在开发 AR 游戏。在特定情况下,我想在统一的场景的一部分(例如在飞机上)播放用户从手机图库中选择的视频。我测试了统一视频播放器,但是当视频大小超过 100 MB 时会延迟很多,甚至纹理也无法显示,只是我可以听到视频声音。

我现在该怎么办?我应该编写一个Java本机插件来在Java中流式传输视频并统一设置纹理吗?

感谢和抱歉英语不好。

    videoPlayer.playOnAwake = false;
    videoPlayer.source = VideoSource.Url;
    videoPlayer.url = url;
    videoPlayer.Prepare();

    //Wait until video is prepared
    while (!videoPlayer.isPrepared)
    {
        Debug.Log("Preparing Video");
        yield return null;
    }

    //Assign the Texture from Video to RawImage to be displayed
    image.texture = videoPlayer.texture;

    //Play Video
    videoPlayer.Play();
Run Code Online (Sandbox Code Playgroud)

我还在编辑器中分配了 AudioSource。只要视频大小低于 10 MB,一切都正常。

c# android video-streaming unity-game-engine vuforia

1
推荐指数
1
解决办法
6207
查看次数

在销毁GameObjects时我应该取消字段吗?

如果通过Inspector设置了一个字段,我应该在销毁GameObject时使其无效吗?Unity会自动执行此操作吗?

public class TestClass : MonoBehaviour
{
    public Image Icon;
    public Button CloseButton;

    private void Start()
    {
        Icon.color = Color.black;
        CloseButton.onClick.AddListener( MyButtonListener );
    }

    private void OnDestroy()
    {
        CloseButton.onClick.RemoveListener( MyButtonListener );

        //DO I NEED THIS?
        Icon = null;
        CloseButton = null;
    }

    private void MyButtonListener() { }
}
Run Code Online (Sandbox Code Playgroud)

c# memory-management unity-game-engine

1
推荐指数
1
解决办法
69
查看次数

Unity Touch输入

我已经建立了一个统一的小游戏.其中,当玩家触摸屏幕时,引脚会产生.我遇到的问题是,当我触摸屏幕时,而不是一个,两个引脚一次产生.我用这个代码 -

 if(Input.touchCount == 1)
    {
        Spawnpin();
    }
Run Code Online (Sandbox Code Playgroud)

c# unit-testing input touch unity-game-engine

1
推荐指数
1
解决办法
299
查看次数

MissingReferenceException:"Attacker"类型的对象已被破坏,但您仍在尝试访问它

我收到上述错误,我尝试使用debug.log打印错误的位置.我正在创造一种坦克obj.哪个实例化了obj.实例化对象是攻击者.

在更新中,我使用foreach循环遍历所有实例化对象.如果找到并且If对象在射程范围内.

void Update () {


        if (attacker!= null  )
        {
            //Debug.Log("inside att");
            attacker = FindObjectsOfType<Attacker>();
        }

        // fire only if attacker is in range 

        if (IfInRange() && attacker!= null && running)
        {

            faceTowardTarget();
            Fire();
        }


    }
    bool IfInRange()
    {// run through all the instantiated attacker
        foreach (Attacker currentAttacker in attacker)
Run Code Online (Sandbox Code Playgroud)

这工作正常,但有些时候会给出上面的结果.在控制台的最后,循环继续进行,currentAttacker最后为空.我试着在控制台中打印它.但它不会进入其他if语句

{   //if attacker is in range

            if (attacker != null )
                {

                    Debug.Log(currentAttacker.GetComponent<Health>().isAlive);

                    if (Vector2.Distance(transform.position, currentAttacker.transform.position) < minDistance)               
                    {

                        attackerPos = currentAttacker.transform;

                        return true;
                    }
                }
                if (currentAttacker …
Run Code Online (Sandbox Code Playgroud)

c# 2d unity-game-engine

1
推荐指数
1
解决办法
223
查看次数