- Home /
Shader forge Toggle
Hey guys i was wandering if anyone knew how to access the toggle or bool of a shader that was created in shader forge.
C Sharp fireBaseObj.renderer.material.??("_crafted", true);
Interesting, I thought material would have a SetBool function. $$anonymous$$ust look into it further
Wisearns answers is the way to go, because there is no boolean Set/Get. See this forum entry
It would be interesting to see the shader code made by Shaderforge ...
Answer by Wisearn · Oct 17, 2014 at 01:47 PM
The material properties does at least have a GetInt and SetInt that you can expose as 0, 1 and convert to/use as a bool.
http://docs.unity3d.com/ScriptReference/Material.GetInt.html (see GetFloat)
So in the properties of the shader something like
Properties {
Crafted ("_Crafted", Range (0, 1)) = 0;
}
and then something like
bool myBool = (renderer.material.GetInt("_Crafted") == 1 ? true : false)
and
renderer.material.SetInt("_Crafted", 1);
(someone might have to correct my code, I haven't actually tried this myself)
Yh i pretty much have done that for now, ins$$anonymous$$d though i changed the toggle inside the shader to a visible value for now. I will send a message to him and see if i can get a solid solution to it. However im guessing it will be what you wrote above. Thanks
Oh and i will check the code when i get home im a bit rusty in csharp, switching from java/uniscript so everything's a bit different for me
Answer by kjustynski · Dec 13, 2016 at 05:14 PM
Toggle node is just nice UI wrapper for Float value. If you want to change its value from script, simply use SetFloat function.
material.SetFloat("_ParamName", 0);
Your answer
Follow this Question
Related Questions
A node in a childnode? 1 Answer
'Sticky' cursor 1 Answer
How to make it so enemies only move towards the player when the player is colliding with an object 1 Answer
input key named : KeyCode.Escape is unkown 2 Answers
Changing material on prefab 0 Answers