Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more..
    Dismiss Notice
  3. Dismiss Notice

Activate dissolve shader at specific time

Discussion in 'Scripting' started by heh223, Feb 6, 2022.

  1. heh223

    heh223

    Joined:
    Jan 2, 2020
    Posts:
    25
    I'm trying to trigger/activate the dissolve shader at the specific point (when an object is enabled), but dissolving starts at the beginning of the scene even if the game object is disabled. Game object is disabled at the beginning but the dissolve shader works independently and then when I activate the game object shader is already dissolved. Can anybody help me with this. I believe it has to be an easy solution but I can not figure it out. Below is the code.
    Code (CSharp):
    1.     Material mat;
    2.     public GameObject objectToDissolve;
    3.  
    4.     private void Start()
    5.     {
    6.         mat = GetComponent<Renderer>().material;
    7.     }
    8.  
    9.     private void Update()
    10.     {
    11.         if (objectToDissolve.activeSelf)
    12.         {
    13.             mat.SetFloat("_DissolveAmount", Mathf.Lerp(0, 1, Time.time / 7));
    14.         }
    15.  
    16.     }
     
    Last edited: Feb 6, 2022
  2. ericbegue

    ericbegue

    Joined:
    May 31, 2013
    Posts:
    1,353
    What do you mean with this statement?
    Code (CSharp):
    1. if (objectToDissolve == enabled)
    2.  
     
  3. heh223

    heh223

    Joined:
    Jan 2, 2020
    Posts:
    25
    Oh my bad. I was doing some testing. It is...
    Code (CSharp):
    1. if (objectToDissolve.activeSelf)
     
  4. ericbegue

    ericbegue

    Joined:
    May 31, 2013
    Posts:
    1,353
    Code (CSharp):
    1. Mathf.Lerp(0, 1, Time.time / 7)
    The third parameter of the Lerp function should be a float betwen 0 and one.
    However, about Time time, the doc says: