Flash animation doesnt work

Hey guys. I made a kinda animation where the enemy should flash up quickly when he gets hit by an attack. Somehow the color isnt loading and i dont know why :frowning: Heres a video of that: 1
My Enemy script where i did it looks like this:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Enemy : MonoBehaviour
{
    public float speed;
    private Transform target;
    public int health = 100;
    public GameObject deathEffect;
    private Material matWhite;
    private Material matDefault;
    SpriteRenderer sr;

    // Start is called before the first frame update
    void Start()
    {
        target = GameObject.FindGameObjectWithTag("Player").GetComponent<Transform>();
        sr = GetComponent<SpriteRenderer>();
        matWhite = Resources.Load("WhiteFlash", typeof(Material)) as Material;
        matDefault = sr.material;
    }

    // Update is called once per frame
    void Update()
    {
        transform.position = Vector2.MoveTowards(transform.position, target.position, speed * Time.deltaTime);
    }

    public void TakeDamage(int damage)
    {
        sr.material = matWhite;

        health -= damage;

        if (health <= 0)
        {
            Die();
        }
        else
        {
            Invoke("ResetMaterial", 0.5f);
        }


    }

    void ResetMaterial()
    {
        sr.material = matDefault;
    }

    void Die()
    {
        Instantiate(deathEffect, transform.position, transform.rotation);
        Destroy(gameObject);
    }

}

Its probably a stupid mistake but im still to nooby to find it lol. I followed a tutorial for that and im not sure about the “reset Material”. I tried to make a Material that has no oppacity and called it ResetMaterial but it still didnt work and now im pretty lost. It would be great if someone could help :slight_smile:

Not sure if this will work, but instead of resources.Load just reference it as a Material like this public Material whiteMat
And use it from the variable.