Im trying to figure out if there is another way the have an Enemy GameObject Chase and follow the Player without needing to having to using “public Transform”, or for a way that the game automatically places the Player Object into the enemy script, or anything like the two examples. Is this possible or am I sol? I could really use the help, thank you.
You can use find with tag to find the player, use singleton, static player reference, initialization with a reference from a manager class.
For movement navmesh also is good
Thank you, ill definitely try that.
Remember for future reference that photographs of code are not a thing.
If you post a code snippet, ALWAYS USE CODE TAGS:
How to use code tags: Using code tags properly
You need to separate your problems out!
You’re thinking of it like this:
- I need another way to chase the player without having to set the player’s transform manually in advance
But it’s really two problems:
- I need a way to make the enemy chase something
- I need a way to tell the enemy about the player
A few reasonable solutions for problem 2 here:
- Use a tag to identify the player
- Use a specific component to identify the player, and search the scene for that component
- Have a singleton game controller that the player registers themselves with, then have the enemies ask the manager about the player
Oh, I’m sorry, I didn’t know. This is my first time posting. Thank you for your input on what is the proper way to post code. I’ll keep that in mind for the future.
ML Agents
Hmm, I’ve never thought about it that way. Thank you for your help, Ill definitely try to figure out with that in mind.