Làm mờ màn hình khi pause game
C# Code
// This script requires a Post-processing package with Depth of Field.
// Attach this to a GameObject with a Post-process Volume.
using UnityEngine;
using UnityEngine.Rendering.PostProcessing;
public class PauseBlur : MonoBehaviour
{
private PostProcessVolume volume;
private DepthOfField dof;
void Start()
{
volume = GetComponent<PostProcessVolume>();
volume.profile.TryGetSettings(out dof);
if(dof != null) dof.enabled.value = false;
}
void Update()
{
if (dof == null) return;
if (Time.timeScale == 0f)
{
dof.enabled.value = true;
dof.focusDistance.value = 0.1f;
}
else
{
dof.enabled.value = false;
}
}
}Tự động áp dụng hiệu ứng Depth of Field để làm mờ màn hình khi game được tạm dừng, yêu cầu gói Post Processing.