- Home /
Prefab Losing Target Transform
I'm making a game where police cars chase the player. I have empty gameobjects around the world instantiating my police cars using a "Police Car" prefab when the player is near it. This same car prefab is also destroyed at a certain distance away. The problem is, my prefab does not keep the "Target Transform" in the "Car AI Control" or the "Car Controller" scripts. This means when the car instantiates, it doesn't follow the player. This seems to happen to all of the prefabs I create. I am using the Unity "AI Sky Car" with my own car body on it. If somebody could help it would be greatly appreciated.
You would need to pass them a reference to the player when you instantiate them. Prefabs cannot store a reference to scene objects and if they have a reference to the player prefab, that is not the same object which you created in the scene.
Thank you for responding @Warmedx$$anonymous$$ints . How would I go about creating a reference to the player?