using UnityEngine;

public class Enviroment : MonoBehaviour
{

    public float envPosX;
    public float envPosY;
    public float envPosZ;
    public float maxCheckDistance = 100f;
    public LayerMask groundLayer;
    public float groundOffset = 3f;
    // Start is called once before the first execution of Update after the MonoBehaviour is created
    void Start()
    {
        groundLayer = LayerMask.GetMask("Ground");
        SnapToGround();
        envPosX = transform.position.x;
        envPosY = transform.position.y;
        envPosZ = transform.position.z;
    }

    // Update is called once per frame
    void SnapToGround()
    {
        RaycastHit hit;

        if (Physics.Raycast(transform.position, Vector3.down, out hit, maxCheckDistance, groundLayer))
        {
            Vector3 pos = transform.position;
            pos.y = hit.point.y + groundOffset;
            transform.position = pos;
        }
    }
}
