- Home /
transform.position not a member???
I have no ideaaaa why im getting this error...somebody please help!!!
ERROR: Assets/Standard Assets/Scripts/FollowPlayer.js(6,50): BCE0019: 'position' is not a member of 'UnityEngine.GameObject'.
var lookAtTarget : GameObject; var speed = 1;
function Update() { var dist = Vector3.Distance(lookAtTarget.position, transform.position);
if (dist < 100)
{
transform.LookAt (lookAtTarget.transform); //look at player
transform.Translate (0,0,speed*Time.deltaTime); //move toward the player
}
}
All im trying to do is have an enemy move towards the player when in range...help please
Answer by Oninji · Oct 21, 2010 at 11:03 PM
Your lookAtTarget var should be
var lookAtTarget : Transform;
i've tried that earlier and im getting these errors now...
PPtr cast failed when dereferencing! Casting from GameObject to Transform! UnityEngine.Transform:get_position() UnityEngine.Transform:get_position() FollowPlayer:Update() (at Assets/Standard Assets/Scripts/FollowPlayer.js:12)
[/Users/build/builds/unity-26/unity-2.6.x/Projects/../Runtime/BaseClasses/BaseObject.h line 655]
I've seen this engine error too, but oddly enough it was only when porting a 2.6 game to 3.0. Did you recently upgrade to 3.0 from 2.6?
Answer by JDonavan 1 · Oct 21, 2010 at 11:26 PM
You should have lookAtTarget.transform.position not lookAtTarget.position.
Your answer
![](https://koobas.hobune.stream/wayback/20220613080401im_/https://answers.unity.com/themes/thub/images/avi.jpg)