I have an FPS Character Controller and an Enemy.When The FPScc enters in to the trigger it makes the Enemy prefab invite to the scene and this enemy has a follow script and a target “Transfrom” variable. The problem is if I delete the Enemy from the scene( because I want it to appear if I hit the trigger…) the Transform variable lose the my target and cant invite the prefab. Can I define my target manually in the script?
Yes.
In the OnTriggerEnter function where you Instantiate the enemy prefab you just need to hand it the new target to follow.
EG. (in C#)
public Object enemyPrefab;
void OnTriggerEnter()
{
GameObject enemy = (GameObject) Instantiate(enemyPrefab, Vector3.zero, Vector3.zero);
enemy.GetComponent("Follow").target = gameObject.transform;
}
Warning Untested code that assumes things about your scripts. May not work at all.
Okey you have exaggerated this a little bit :D. Btw I figured out the answer what I want:
- public var thePlayer : Transform;
- thePlayer = GameObject.Find( “First Person Controller” ).transform;