- Home /
2D | Material Shader - How to adjust value of material by slider?
Hello please anyone in this world know something about this, help me
I want to acceess the material parameter. To increase value of HSVA Adjust, paratemer "_HSVAAdjust" WHILE increase it with slider when play game.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SliderColor3 : MonoBehaviour
{
Renderer rend;
// Start is called before the first frame update
void Start()
{
rend = GetComponent<Renderer> ();
rend.material.shader = Shader.Find ("HSVAAdjust");
}
// Update is called once per frame
public void textUpdate4(float value)
{
//float HsvaAdjust = (0f, 0f, value*10, 0f);
rend.material.SetFloat ("_HSVAAdjust", 0.5f);
}
}
Answer by saschandroid · Apr 25, 2019 at 06:14 AM
The name of the shader should be exactly the displayed name:
Shader.Find ("Custom/HSVRangeShader");
To get the name of the value to change, you can click on 'Edit Shader' (little gear icon in material settings). Now you can see all changeable values with their correct names.
Hey thanks for helping it do work but in different material. (instance material?)
After play, it produces new instance material? and the instance it's not working l like original material down below.
How to eli$$anonymous$$ate the instance from exist and the code must work on original material and not create new instance?
O$$anonymous$$G I GOT THE ANSWER, JUST CHANGE $$anonymous$$aterial TO shared$$anonymous$$aterial <33
Answer by staryzhelios · Apr 25, 2019 at 07:15 AM
Hey thanks for helping it do work but in different material. (instance material?)
After play, it produces new instance material? and the instance it's not working l like original material down below.
How to eliminate the instance from exist and the code must work on original material and not create new instance?
this is my update code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SliderColor3 : MonoBehaviour
{
Renderer rend;
float xvalue = 0f;
float yvalue = 0f;
float zvalue = 0f;
// Start is called before the first frame update
void Start()
{
rend = GetComponent<Renderer> ();
rend.material.shader = Shader.Find ("Custom/HSVRangeShader");
}
// Update is called once per frame
public void textUpdate4(float slidervalue)
{
//zvalue = zvalue*0.10f;
zvalue = slidervalue;
rend.material.SetColor ("_HSVAAdjust", new Vector4 (xvalue,yvalue, zvalue*1f, 1f));
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612200153im_/https://answers.unity.com/themes/thub/images/avi.jpg)