简体   繁体   中英

error CS1503: Argument 1: cannot convert from 'UnityEngine.XR.XRNode' to 'string

public float[,,,] HmdPosition = new float [1,1,6,1];
public Vector3 HmdRotation;
....
....
HmdPosition[0, 0, i,0] = UnityEngine.XR.InputTracking.GetLocalPosition(node);
HmdRotation = GameObject.Find(node).transform.rotation;

I am using this code to save the parameters(transform) of HMD and controller both rotation and position in an array but I got these two errors :

first : "error CS0029: Cannot implicitly convert type 'UnityEngine.Quaternion' to 'float' " second: "error CS1503: Argument 1: cannot convert from 'UnityEngine.XR.XRNode' to 'string'" Does anyone have any idea?

(I guess I have to change the definition of my array but how? and sorry that I'm not master in unity and c# both) btw is it possible to save the local position and orientation the HMD and controllers with this method?

  1. XRNode is an enum .. you are using it like a string in

     Find(node)

    rather use

     Find(node.ToString())
  2. You are assigning a Quaternion to a Vector3 variable in

     HmdRotation = GameObject.Find(node.ToString()).transform.rotation;

    rather use eg

     HmdRotation = GameObject.Find(node.ToString()).transform.eulerAngles;
  3. You are assigning a Vector3 to a float in

     HmdPosition[0, 0, i, 0] = UnityEngine.XR.InputTracking.GetLocalPosition(node);

    You either can only store one of the components x , y or z or should change your data structure. A Vector3 as the name says is made of three float components not one.


In general: What is a 4-dimensional array good for if 3 of your dimensions anyway only allow one single layer..??

It is difficult to give further advice without seeing the rest of your code and knowing your actual intentions but

is it possible to save the local position and orientation the HMD and controllers with this method?

Well currently you get a bunch of exceptions .. so no!

What you describe would need to store one Vector3 position + one Quaternion or Vector3 rotation. And this whole thing three times for the HMD + two controllers.

So if you really want to serialize this into a float array in total this would require at least 18 values.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM