I want my PlayerObj(Name of the Gameobject) toc check if an enemy is in a specific radius(enemy name: Enemy, enemy tag: Enemy) and then I wan the playerObj to turn towards that enemy. I am completly out of ideas, tired and honestly I’m nearly about to quit my game project. Pls help( with code)
If there are multiple enemies you need one of the following:
2D game: you want Physics2D.OverlapCircle
3D game: you want Physics.OverlapSphere
Both return an array and you can specify a layer to mask the results. If there is only one enemy, you can use:
(enemy.transform.position - player.transform.position).magnitude
and check that for being less than your required radius.
As for looking at a player, you can simply use:
transform.LookAt(enemy.transform.position)