Skip to main content
formatted function calls and added asset package information in case the link changes in the future
Source Link

I want to know is there a way of using Mathf.SmoothStepMathf.SmoothStep to control the float of a variable? You see I downloaded this package ("Frost Effect by Steven Craeynest") on unity assets storeUnity Asset Store and created a IEnumerator OnTriggerEnter2D IEnumerator OnTriggerEnter2D (in a new script) to control the effect once my player hits an orb, making it slow down but now I want to add an animation. Rather than having it appear of the screen and then disappearing, I want to make the frost effect slowly come in, kinda like controlling the frost amount in the inspector. It is possible, because I tried doing it like this:

(This is attachattached to orb)

I want to know is there a way of using Mathf.SmoothStep to control the float of a variable? You see I downloaded this package on unity assets store and created a IEnumerator OnTriggerEnter2D (in a new script) to control the effect once my player hits an orb, making it slow down but now I want to add an animation. Rather than having it appear of the screen and then disappearing, I want to make the frost effect slowly come in, kinda like controlling the frost amount in the inspector. It is possible, because I tried doing it like this:

(This is attach to orb)

I want to know is there a way of using Mathf.SmoothStep to control the float of a variable? You see I downloaded this package ("Frost Effect by Steven Craeynest") on Unity Asset Store and created a IEnumerator OnTriggerEnter2D (in a new script) to control the effect once my player hits an orb, making it slow down but now I want to add an animation. Rather than having it appear of the screen and then disappearing, I want to make the frost effect slowly come in, kinda like controlling the frost amount in the inspector. It is possible, because I tried doing it like this:

(This is attached to orb)

added 429 characters in body
Source Link

Second Edit Because so far this is what I have:

        GameObject.Find("Main Camera").GetComponent<FrostEffect>().enabled = true;
        float duration = 2f;
        DOTween.To(x => FrostEffect.FrostAmount = x, 0.0f, 0.34f, duration)
            .OnComplete(()=>DOTween.To(x => FrostEffect.FrostAmount = x, 0.34f, 0.0f, duration));
        Time.timeScale = 0.05f;
        yield return new WaitForSeconds (6.5f);
        Time.timeScale = 1f;

Second Edit Because so far this is what I have:

        GameObject.Find("Main Camera").GetComponent<FrostEffect>().enabled = true;
        float duration = 2f;
        DOTween.To(x => FrostEffect.FrostAmount = x, 0.0f, 0.34f, duration)
            .OnComplete(()=>DOTween.To(x => FrostEffect.FrostAmount = x, 0.34f, 0.0f, duration));
        Time.timeScale = 0.05f;
        yield return new WaitForSeconds (6.5f);
        Time.timeScale = 1f;
Source Link

Unity2D: Frost Effect Animation

I want to know is there a way of using Mathf.SmoothStep to control the float of a variable? You see I downloaded this package on unity assets store and created a IEnumerator OnTriggerEnter2D (in a new script) to control the effect once my player hits an orb, making it slow down but now I want to add an animation. Rather than having it appear of the screen and then disappearing, I want to make the frost effect slowly come in, kinda like controlling the frost amount in the inspector. It is possible, because I tried doing it like this:

(This is attach to orb)

// Use this for initialization
void Start () { 
}
    
IEnumerator OnTriggerEnter2D(Collider2D other)
{
    if (other.tag == "Player") {
        //frost.enabled = true; 
        GameObject.Find("Main Camera").GetComponent<FrostEffect>().enabled = true;
        FrostEffect.valToBeLerped = Mathf.SmoothStep(0, 1f, FrostEffect.FrostAmount);
        yield return new WaitForSeconds (1.01f);
        FrostEffect.valToBeLerped = Mathf.SmoothStep(1, 0, FrostEffect.FrostAmount);
        GameObject.Find("Main Camera").GetComponent<FrostEffect>().enabled = false;
    }
}

But it's still appearing automatically rather than it slowly coming in like an animation. Anyway this is the frost effect script I downloaded from the assets store:

(Attach to the main camera)

public static float FrostAmount = 0.3f; //0-1 (0=minimum Frost, 1=maximum frost)
public static float valToBeLerped = 0;
public float EdgeSharpness = 1; //>=1
public float minFrost = 0; //0-1
public float maxFrost = 1; //0-1
public float seethroughness = 0.2f; //blends between 2 ways of applying the frost effect: 0=normal blend mode, 1="overlay" blend mode
public float distortion = 0.1f; //how much the original image is distorted through the frost (value depends on normal map)
public Texture2D Frost; //RGBA
public Texture2D FrostNormals; //normalmap
public Shader Shader; //ImageBlendEffect.shader

private Material material;

private void Awake()
{
    material = new Material(Shader);
    material.SetTexture("_BlendTex", Frost);
    material.SetTexture("_BumpMap", FrostNormals);
}

private void OnRenderImage(RenderTexture source, RenderTexture destination)
{
    if (!Application.isPlaying)
    {
        material.SetTexture("_BlendTex", Frost);
        material.SetTexture("_BumpMap", FrostNormals);
        EdgeSharpness = Mathf.Max(1, EdgeSharpness);
    }
    material.SetFloat("_BlendAmount", Mathf.Clamp01(Mathf.Clamp01(FrostAmount) * (maxFrost - minFrost) + minFrost));
    material.SetFloat("_EdgeSharpness", EdgeSharpness);
    material.SetFloat("_SeeThroughness", seethroughness);
    material.SetFloat("_Distortion", distortion);
    ///Debug.Log("_Distortion: "+ distortion);

    Graphics.Blit(source, destination, material);
}

Thank you. :)