This is a part of a camera script that zooms in - out with te mouse wheel.
The problem is taht if I have a terrain with hills, the camera moves through them.
How can I make the camera moves a little bit upper when it touches the floor?
I think some raycast should be used, right?
if (Input.GetAxis("Mouse ScrollWheel") < 0) // back
{
Camera.main.transform.position += Vector3(0, zoomingSpeed, 0);
}
if (Input.GetAxis("Mouse ScrollWheel") > 0) // forward
{
Camera.main.transform.position += Vector3(0, -zoomingSpeed, 0);
}
if (transform.position.y < minDistance)
{
transform.position.y = minDistance;
}
if (transform.position.y > maxDistance)
{
transform.position.y = maxDistance;
}