private GameObject _player;
RaycastHit hitInfo;
private void Start()
{
_player = FindObjectOfType<Player>().gameObject; //Всмето Player любой другой скрип можешь указать, который на нем есть.
}
private void FixedUpdate()
{
CastRayToPlayer();
}
private void CastRayToPlayer()
{
if(Physics.Raycast(transform.position, (_player.transform.position - transform.position), out hitInfo))
{
Debug.Log(hitInfo.collider.name);
if(hitInfo.collider.GetComponent<Player>() != null)
Move();
}
}
private void Move()
{
Debug.Log("Move");
}
private void OnDrawGizmosSelected()
{
if(_player != null)
Gizmos.DrawRay(transform.position, (_player.transform.position - transform.position));
}