[Solved]Control dissolve timer ?

Hi.
I’m trying to access my shader material to my script to control dissolve timer.

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

public class uuyyy : MonoBehaviour
{
    public Shader myMeshShader;
    public float shadertime = 0; // dessolve value
   
    void Start()
    {

        myMeshShader = gameObject.GetComponent<Shader>();
        shadertime = myMeshShader.set ............. // setGlobalFloat !!
               
    }
   
}

Hey Dude,

Look at this doc for further reference…

You want the Material.SetFloat() command.
If you click the little cog icon in the inspector for the shader and go edit, you will get a list of editable values and somewhere you will find the dissolve value. May look something like _DesolveValue

Let me know if that does not work.

Thank you your respond. actually, you right about the SetFloat. I should use it. Any way Here is the full script.

   public Material _shader;
    public float timer = 0;

    // Start is called before the first frame update
    void Start()
    {

     //   _shader = gameObject.GetComponent<Renderer>().material; // this line will duplicate the mate !! I don't know why ? So, no need to use it
        _shader.SetFloat("Vector1_F92326F1", timer); // How I get the name from shader file..look at image down.

    }

    // Update is called once per frame
    void Update()
    {
       
        if (Input.GetKeyDown(KeyCode.Space))
        {
            timer += 0.01f;
            _shader.SetFloat("Vector1_F92326F1", timer);
        }
    }

Hope this will help more people like me.

Great!!! Glad you got it to work.

just to add to it, you can avoid possible errors by adding a clamp to the value. As I would assume the dissovle value is a range of 0-1

timer += 0.01f;
timer = mathF.Clamp(timer, 0, 1); //Stops the number from going passed 1
_shader.SetFloat("Vector1_F92326F1", timer);
1 Like

Cool. I will put this in my mind.
Thank you so much.

Note that you can expose variables from the Shader Graphs, and it’s possible to assign different name for them instead of randomized hash.