- Home /
'position' is not a member of 'UnityEngine.Vector3'.
I have a variable that changes:
var targetPoint : Vector3 = Camera.main.ScreenToWorldPoint(new Vector3(Screen.width / 2, Screen.height / 2, 0));
targetPoint += Camera.main.transform.forward * mPointDistance;
Then I have:
var distance = Vector3.Distance (transform.position, targetPoint.position);
The problem is that it does not recognize targetPoint as a Vector3. Why? I'm sure targetPoint doesn't change into something else here, it just adds a new position to it. Does anyone know why this isn't working?
Answer by perchik · Mar 12, 2014 at 05:48 PM
Your problem is not "it does not recognize targetPoint
as a Vector3" as you claim, but rather that it does see that targetPoint
is a Vector3, and Vector3 doesn't have a .position member.
Just remove the .position because Vector3.Distance expects to get two vectors. transform is of type Transform
and thus you have to do .position, to get the vector3 from it. targetPoint is already a vector3 so you don't have to do anything to it:
var distance = Vector3.Distance (transform.position, targetPoint);
Oh yeah, because it was Vector3.Distance, I thought it should have been Vector3.position aswell!