33 lines
873 B
C#
33 lines
873 B
C#
using UnityEngine;
|
|
|
|
namespace StixGames.GrassShader
|
|
{
|
|
public class SimpleMover : MonoBehaviour
|
|
{
|
|
public float speed = 5f;
|
|
|
|
public float height = 0.5f;
|
|
|
|
public LayerMask rayCastLayers;
|
|
|
|
private void Update()
|
|
{
|
|
base.transform.position += speed * Vector3.right * Input.GetAxis("Horizontal") * Time.deltaTime;
|
|
base.transform.position += speed * Vector3.forward * Input.GetAxis("Vertical") * Time.deltaTime;
|
|
RaycastHit hitInfo;
|
|
if (Physics.Raycast(new Ray(base.transform.position + Vector3.up * 1000f, Vector3.down), out hitInfo, float.PositiveInfinity, rayCastLayers))
|
|
{
|
|
Vector3 position = base.transform.position;
|
|
position.y = hitInfo.point.y + height;
|
|
base.transform.position = position;
|
|
}
|
|
else
|
|
{
|
|
Vector3 position2 = base.transform.position;
|
|
position2.y = height;
|
|
base.transform.position = position2;
|
|
}
|
|
}
|
|
}
|
|
}
|