|
My object shoots at player just fine using the look at command and using the : var target : Transform; Where target is the game object that's being targeted. But, When shoot object is destroyed and then respawned (instantiated) the target variable is not active. How do I make the target variable the same when it's instantiated. Example: object shoots at target, object dies, object respawned but shoots wrong
(comments are locked)
|
|
The target variable in your LookAt monobehaviour needs to somehow be updated to the new gameobject. One of the ways to achieve this is to make the code that does the respawning, also inform the lookat script about the "new thing to look at".
(comments are locked)
|
|
The variable will be empty as it is a reference to a gameobject that's not part of the prefab. A simple solution is to set the variable through code, this would give something like this:
Of course, this assumes you gave the player Tag Player and that you're interested in the transform of the player. If you want to store the GameObject of the player, replace
(comments are locked)
|
