![alt text][1]
[1]: /storage/temp/182650-screenshot-2021-06-26-194508.png
RaycastHit hit;
var rayDirection = Player.transform.position - Enemy.transform.position;
Debug.DrawRay(transform.position, rayDirection);
if (Physics.Raycast(transform.position, rayDirection, out hit)) {
if (hit.collider.gameObject.tag == "Player"){
Debug.Log("Works");
}
else {
}
}
This code is inside of the update function. Basically, the ray is drawn in the right position, but the Debug.Log("Works"); is never printed into the console. I am trying to make this so the enemy will only shoot at the player when they are in direct line of sight.
Thanks for the help!
↧