Narratech_TFG-Fernandez/IAV Robot/Assets/Liquid Snake/Scripts/test/Torreta.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
///    PARA DEBUGUEAR
/// GameObject de debug, para comprobar si el agacharse y tumbarse 
/// se hacía correctamente y a partir de X altura dejaba de detectarle.
/// </summary>
public class Torreta : MonoBehaviour
{
    void FixedUpdate()
    {
        // Bit shift the index of the layer (8) to get a bit mask
        int layerMask = 1 << 8;

        // This would cast rays only against colliders in layer 8.
        // But instead we want to collide against everything except layer 8. The ~ operator does this, it inverts a bitmask.
        layerMask = ~layerMask;

        RaycastHit hit;
        // Does the ray intersect any objects excluding the player layer
        if (Physics.Raycast(transform.position, transform.TransformDirection(Vector3.forward), out hit, Mathf.Infinity, layerMask) && hit.transform.tag == "Player")
        {
            Debug.DrawRay(transform.position, transform.TransformDirection(Vector3.forward) * hit.distance, Color.yellow);
        }
        else
        {
            Debug.DrawRay(transform.position, transform.TransformDirection(Vector3.forward) * 1000, Color.white);
        }
    }
}
