Hello. I'm a solo dev working on a 2d side scroller game.
Recently, I made a character that uses the clipping function to hide the body beneath the ground, and the animation turned out to be great.
However, the hit-flickering code I made doesn't apply to the material parameter during the animation that uses a clipping attachment.
What I'm trying to say is, well, here is an example.
here's a code I made for the hit-flickering.
public class HitFlickering : MonoBehaviour
{
public MeshRenderer meshRenderer;
public string colorProperty = "_OverlayColor";
public string brightnessProperty = "_Brightness";
private bool flashing = false;
MaterialPropertyBlock block;
// Start is called before the first frame update
IEnumerator flashCoroutine()
{
yield return new WaitForSeconds(0.1f);
meshRenderer.material.SetColor(colorProperty, new Color(0, 0, 0, 0));
meshRenderer.material.SetFloat(brightnessProperty, 1);
flashing = false;
yield break;
}
public void OnTriggerEnter2D(Collider2D other)
{
if (other.gameObject.layer == 20 || other.gameObject.layer == 10)
{
flashing = true;
meshRenderer.material.SetColor(colorProperty, new Color(1, 1, 1, 0.7f));
meshRenderer.material.SetFloat(brightnessProperty, 2);
StartCoroutine(flashCoroutine());
}
}
}
And here is a video I took to show you the problem.
VIDEO
When he is doing the intro animation, the clipping attachment is activated. After the animation is finished, the attachment becomes disabled. And as you can see, the flickering doesn't work when the animation clip has the activated clipping attachment. Is this a bug from Spine? Or is this a Unity shader problem that I don't know? (and if it is, I hope I can get the solution from here, since I don't know anything about shaders, to be honest. :tear: )
In case if you need more info, I'm using the URP and the material's shader is the default URP/2D/Spine/Sprite.