How to assign a transform object to Prefab ?

Hello Developers, I’ve got a problem right here. I’ve got 2 spaceships and their AI script. I can’t assign my game object to theese scripts. I think that’s because of i used “Transform” method. But When i change it to “GameObject.FindWithTag(“Player”);” transform method and follow method colappses. So what should i do ?

enter code herevar moveSpeed : float;
var player : Transform;
var distanceToPlayer : float;

function Update() 
{

transform.LookAt(player);

if ((Vector3.Distance(transform.position, player.position) > distanceToPlayer))
{
		transform.position += transform.forward * moveSpeed * Time.deltaTime;
}

else

{

transform.rotation.y = 180;
transform.position += transform.forward * moveSpeed * Time.deltaTime;

}

}

my code is this.

Age 14, Turkey.

player = GameObject.FindWithTag(“Player”);
target = player.transform;

get the gameobject, then get the gameobjects transform. this worked for me, hope it works for you as well!

It doesn’t have anything to do with your use of a public Transform variable to hold a reference to the player. Instead, it is probably because Unity doesn’t serialize scripts (and public variables) until all scripts pass compilation. Serialization is the feature that makes stuff appear in the Inspector. I don’t see anything wrong with your script as posted above, but perhaps there are still compiler errors elsewhere in your code?

Clear all compiler errors, and then try again. “Player” should appear in the Inspector in the editor for this script, and then you can drag the gameobject onto it.

Make your player a prefab.