Files
FutureMen2/Assets/_FutureMen2/Scripts/Plugins/LockYToGround.cs

22 lines
519 B
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class LockYToGround : MonoBehaviour
{
public LayerMask groundMask;
public float offsetY = 0f;
void LateUpdate()
{
Ray ray = new Ray(transform.position + Vector3.up, Vector3.down);
if (Physics.Raycast(ray, out RaycastHit hit, 10f, groundMask))
{
Vector3 pos = transform.position;
pos.y = hit.point.y + offsetY;
transform.position = pos;
}
}
}