Okay I’ve been chipping at this for days now, posting far too many questions on the forums and Unity answers. I’m having trouble with my enemy, here is the script:
var LookAtThis : Transform;
var elaser : Transform;
var damp = 2;
function Update () {
if(Vector3.Distance(LookAtThis.position,transform.position) < 800){
var rotate = Quaternion.LookRotation(LookAtThis.position - transform.position);
transform.rotation = Quaternion.Slerp(transform.rotation, rotate,damp * Time.deltaTime);
transform.Translate(0,0, 10 * Time.deltaTime);
}
}
InvokeRepeating("fireAtPlayer",1,2);
function fireAtPlayer() {
if(Vector3.Distance(LookAtThis.position,transform.position) < 800){
Instantiate(elaser,transform.Find("espawnpoint").position,transform.rotation);
}
}
function OnCollisionEnter(hit : Collision) {
if(hit.gameObject.tag == ("Player"))
Debug.Log("Watch it!");
}
So I’m trying to make this enemy ship into a prefab but I cant drag a gameObject into the Player var, I did some research and I guess you cant do that unless that gameObject is also a prefab, which seams to make sense. But when I drag a prefab into that var then the enemy will move to the position the player prefab is at game start, but it will not follow the prefab when it moves.
I’ve already established that the script is attached to the correct object of the player.
I’m dying for some help, any kind of tip is greatly appreciated. this doesn’t seam to make any sense.