- Home /
Prefab can't select target Prefab
First of all I'm making a top down shooter, I have a mothership prefab which spawns a dropship prefab and in that dropship prefab there is a script transform.LookAt(target); My problem is in the prefab of the dropship. I try to set its target for the prefab for every dropship that will spawn by the mothership in the inspector which should be earth but it doesn't show any assets that are possible to select at all. I made earth a prefab, and this script works when I just put it on a dropship already in the scene (not as a prefab) it shows all kinds of assets it can target but not from within the prefab itself. How do I get the prefab to show earth in the prefab inspector?
Answer by whydoidoit · Sep 16, 2012 at 10:59 AM
A prefab cannot target a scene object using the Inspector (this is logical because a prefab can be instantiated in any scene) - instead you need to assign the target during Awake or Start. You might have a string variable with the name of the game object to target and then use that to find the actual object when the prefab is instantiated.
In addition to $$anonymous$$ike's answer you could cache the transform at the very start. If earth has a script then you can do this:
static var earthTransform : Transform;
function Start () {
earthTransform = transform;
}
Then call it from outside the script:
target = earthScript.earthTransform;