Instantiate coming up with errors for unknown reasons

I have a script that declares this function:

static var targeter = null;

public function beginTarget(targtype:String,targrange:int,targAoE:int):void

{

 if (targtype == "Projectile")
 {
	 targeter = Instantiate(ProjectileTargeter,transform.position,transform.rotation);
	 
	 
 }

}

For some reason, it comes up with this error:

(9,41): BCE0005: Unknown identifier: ‘ProjectileTargeter’.

I have a prefab ProjectileTargeter. Why is it coming up with that error? That’s exactly how previous examples in Unity Scripting documentation have presented Instantiate being used…

Thanks!

1 Answer

1

Instantiate does not read the names of your prefabs. You have to do

var projectileTargeter: GameObject;

And pull your ProjectileTargeter-Prefab into the slot in the editor.

Or you put the ProjectileTargeter-Prefab in your resources-folder and use Resources.Load(), but that’s slowish

Please use error-codes as tag.

Greetz, Ky.

Thanks :) I'll remember to put the error code as a tag next time.