Hello I have bean making my game and I created a booster for my car and I want to have vignette effect when I step on it, I don't know how to make a script to get the post processing and change the vignette thing. Thanks!
CodePudding user response:
How to get the volume parameters in URP and HDRP are similar to each other, in the following code, after entering the desired volume in the hierarchy, you can carefully see the names of the components mounted on the volume at start.
using UnityEngine.Rendering;
using UnityEngine.Rendering.HighDefinition; // .Unvirsal for urp
///...
public Volume volume;
public void Start()
{
volume.profile.components.ForEach(c => Debug.Log(c.GetType().Name)); // displays the volumes components name, for e.g: Fog, HDRISKY, Bloom
}
Now in the variable change method, all you have to do is get the component via TryGet
and change the value.
if (volume.profile.TryGet(out Vignette vignette)) // for e.g set vignette intensity to .4f
{
vignette.intensity.value = .4f;
}
CodePudding user response:
In Unity, how to make the fading and fading effect of UI objects glowing?
For example, there is a sprite picture with a halo of the moon.
We can add a CanvasGroup component to it.
The alpha value on the component controls the transparency of the image, from 0 to 1.
Then we can achieve the glowing halo effect by controlling the change of the Alpha value cycle in the code.
Here is the code:
private CanvasGroup moonCanvasGroup;
private float flashSpeed=0.2f;
private bool isOn = true;
private float maxAlpha = 0.6f;
private float minAlpha = 0.05f;
void Start ()
{
moonCanvasGroup = GetComponent<CanvasGroup>();
}
void Update ()
{
if (moonCanvasGroup.alpha < maxAlpha && isOn)
{
moonCanvasGroup.alpha =flashSpeed* Time.deltaTime;
}
else
{
isOn = false;
moonCanvasGroup.alpha -=flashSpeed* Time.deltaTime;
if (moonCanvasGroup.alpha <minAlpha)
{
isOn = true;
}
}
}
Then mount the script on the picture, and the effect of the moon glowing is completed.