Why this small scipt isn’t working.
private var PlayerEn : GameObject = GameObject.Find("Player");
function Update () {
if (Vector3.Distance(PlayerEn.transform.position, transform.position) < 25)
{
if(PlayerEn)
{
transform.LookAt(PlayerEn.transform.position);
}
}
}
Turret just “don’t want” to look at me.
Did you check if all the booleans you request are true? Maybe add a Debug.Log(PlayerEn); and Debug.Log(Vector3.Distance(PlayerEn.transform.position, transform.position));
/agree with Wmellema.
if GameObject.Find(“Player”) isn’t successful, then PlayerEn would probably be null, failing the if check below. Also are you sure the distance is less than 25?
I think that other problem can be the parameter passed in the LookAt function. you should use thre transform instead the transform.position.
transform.LookAt(PlayerEn.transform**.position**);
Oops!
private var PlayerEn : GameObject = GameObject.Find("Player");//That must be called only in the main thread
function Update () {
if (Vector3.Distance(PlayerEn.transform.position, transform.position) < 25)
{
if(PlayerEn)
{
transform.LookAt(PlayerEn.transform.position);//the position command there is WROOOOOOOONG!
}
}
}
tipic fail. Anyways, the console always tell you these kind of errors amd them are easy to repair.