Files
Fishing2/Packages/com.nwh.dynamicwaterphysics/Runtime/Utility/UnderwaterFog.cs
2026-02-27 17:44:21 +08:00

47 lines
1.7 KiB
C#

// ╔════════════════════════════════════════════════════════════════╗
// ║ Copyright © 2025 NWH Coding d.o.o. All rights reserved. ║
// ║ Licensed under Unity Asset Store Terms of Service: ║
// ║ https://unity.com/legal/as-terms ║
// ║ Use permitted only in compliance with the License. ║
// ║ Distributed "AS IS", without warranty of any kind. ║
// ╚════════════════════════════════════════════════════════════════╝
#region
using UnityEngine;
#endregion
namespace NWH.DWP2
{
/// <summary>
/// Simple utility script that enables Unity fog when the main camera goes underwater.
/// Attach this script to any GameObject in the scene and assign the water surface transform.
/// </summary>
public class UnderwaterFog : MonoBehaviour
{
/// <summary>
/// Transform of the water surface. Used to determine if camera is underwater.
/// </summary>
public Transform waterTransform;
private void Update()
{
Camera mainCamera = Camera.main;
if (mainCamera == null || waterTransform == null)
{
return;
}
if (mainCamera.transform.position.y < waterTransform.position.y + 0.001f)
{
RenderSettings.fog = true;
}
else
{
RenderSettings.fog = false;
}
}
}
}