Java 向量3值赋值似乎被忽略

Java 向量3值赋值似乎被忽略,java,c#,android,unity3d,Java,C#,Android,Unity3d,正在开发Unity 5.6.2f1和Android 4.3。 到目前为止搜索了6个小时没有理解,仍然可能是我的一个参考/价值误解,非常需要帮助 float nx = pose.Get<AndroidJavaObject>("tx").Call<float>("floatValue"); Debug.Log("nx type is " + nx.GetType() + " and value is " + nx); float testZ = 3;

正在开发Unity 5.6.2f1和Android 4.3。 到目前为止搜索了6个小时没有理解,仍然可能是我的一个参考/价值误解,非常需要帮助

    float nx = pose.Get<AndroidJavaObject>("tx").Call<float>("floatValue");
    Debug.Log("nx type is " + nx.GetType() + " and value is " + nx);
    float testZ = 3;
    Debug.Log("testZ type is " + testZ.GetType() + " and value is " + testZ);
    Vector3 otherPosition = new Vector3(nx, 2.2f, testZ);
    Debug.Log("otherPosition type is " + otherPosition.GetType() + " and value is " + otherPosition);
float nx=pose.Get(“tx”).Call(“floatValue”);
Log(“nx类型为“+nx.GetType()+”,值为“+nx”);
浮动测试z=3;
Log(“testZ类型为“+testZ.GetType()+”,值为“+testZ”);
向量3其他位置=新向量3(nx,2.2f,testZ);
Log(“otherPosition类型为“+otherPosition.GetType()+”,值为“+otherPosition”);
相应的日志显示:

I/Unity(18922):nx类型为系统。单个,值为0.0325

I/Unity(18922):testZ类型为System.Single,值为3

I/Unity(18922):其他位置类型为UnityEngine.Vector3,值为(0.0,2.2,3.0)


有关姿势的更多信息:

AndroidJavaObject pose = display.Get<AndroidJavaObject>("pose");
AndroidJavaObject pose=display.Get(“pose”);

pose.Get(“tx”)
应该返回一个Java浮点对象

已经尝试将nx声明为脚本的私有浮点成员,但没有任何更改

我什么都不知道了。

事实上。。。一切都很好。 调用
Debug.Log(vector3Obj)
时,将调用
Vector3#ToString()
。这是正常的

但是,Vector3的ToString覆盖将其浮点值舍入为最接近的0.1。这就是导致问题的原因:
0.0325
被四舍五入为“0.0”,这就是您在调试输出中得到结果的原因。vector3对象仍保留0.0325的值,但该值太小,在
vector3#ToString()
中转换为字符串时无法与0区分

试试这个:

Debug.Log("otherPosition type is " + otherPosition.GetType()
  + " and value is " + (otherPosition*10));
事实上一切都很好。 调用
Debug.Log(vector3Obj)
时,将调用
Vector3#ToString()
。这是正常的

但是,Vector3的ToString覆盖将其浮点值舍入为最接近的0.1。这就是导致问题的原因:
0.0325
被四舍五入为“0.0”,这就是您在调试输出中得到结果的原因。vector3对象仍保留0.0325的值,但该值太小,在
vector3#ToString()
中转换为字符串时无法与0区分

试试这个:

Debug.Log("otherPosition type is " + otherPosition.GetType()
  + " and value is " + (otherPosition*10));

赛尔夫确实开枪自杀了。谢谢你,德拉科,回答速度也很快。@J.Jacobs-VP呃,之所以速度如此之快,是因为我浏览了新的问题列表,看到了你的问题,然后说“哦,我知道这是什么。”很高兴能帮上忙:)我真的开枪了。谢谢你,德拉科,回答速度也很快。@J.Jacobs-VP呃,速度的提高只是因为我导航到了新的问题列表,看到了你的问题,然后说“哦,我知道这是什么。”很高兴为你提供帮助:)