2
\$\begingroup\$

Effect that im refering to: http://youtu.be/jaBY83WvS3M#t=05m36s

How could I achieve this kind of red lightning/flashing/shadowy effect in Unity3D for a 2D game? I'm trying to think of a way but I'm not that good with shaders or the particle system if thats even the right way to do it.

So I'm looking for any advice on how to achieve this or point me to the right direction.

\$\endgroup\$
3
\$\begingroup\$

Attached to every sprite is a SpriteRenderer component which has a color property. You can use that property to recolor the sprite. The color is applied multiplicative to the sprite, so pure red means all color channels but red are filtered out and the scene becomes shades interpolated between pure black and pure red. This should look very similar to the effect in that video:

gameObject.GetComponent<SpriteRenderer>().color = Color.red;

This is how it looks in the game:

recoloring a unity sprite

However, that will only recolor that one sprite this script is attached to. Attaching it to every single sprite in your game might be a bit tedious to set up and might also be quite inefficient at runtime. But when you want to change the color of all sprites in the game, you can abuse the fact that all sprites by default share the "Sprites-Default" material. This material also has a color, and changing it has the same effect as changing it on the SpriteRenderer. So you just need a script with a reference to any sprite in your scene and then do:

anySprite.GetComponent<SpriteRenderer>().sharedMaterial.color = Color.red;

to make them all red. As a starting point you can use this script I just hacked together and attach it to one sprite. It will cause all sprites in your scene to blink red:

using UnityEngine;

public class Blink : MonoBehaviour {

    private static readonly Color DEFAULT_COLOR = Color.white;
    private float blinkPhase = 0.0f;

    public float blinkSpeed = 1.0f;
    public Color color = Color.red;

    void Update () {
        blinkPhase += blinkSpeed * Time.deltaTime;
        if (blinkPhase >= 1.0 || blinkPhase <= 0.0) blinkSpeed = -blinkSpeed;
        gameObject.GetComponent<SpriteRenderer>().sharedMaterial.color = Color.Lerp(DEFAULT_COLOR, color, blinkPhase);
    }
}

If you want any sprites to not be affected by this (like your UI, for example), create a new Material with a different name, set its shader to "Sprites->Default" so it behaves like the normal sprite material and assign it to any sprites you want to be exempt.

\$\endgroup\$
0
\$\begingroup\$

I think I would start with simply putting a UI panel that covers the entire screen, and most of the time is disabled. When you want the effect, enable it and change the color.

Alternatively, you could use a red light source, and make a 2.5D game. That's basically what I suspect was done in Diablo.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.