- Home /
How to acces Shininess from a Shader in script C#
I have a GameObject which is a cube and on the cube it has a texture on it. Ment for as a background, what I want to do now is accesing the GameObject (cube) then accesing the Shader (it's on Bumped Specular) and then I want to acces the Shininess to tweak in script which can gives my background a cool effect during my game.
BTW: Sorry for my bad English, if you didn't understand what I said ask me for explanation.
Thanks in advance.
Answer by Piflik · Jan 14, 2013 at 09:08 PM
Read:
renderer.material.GetFloat("_Shininess");
Write:
renderer.material.SetFloat( "_Shininess", someValue);
The max value you can adjust via Inspector is 128. The $$anonymous$$ value is 1 IIRC.
Damn, I was thinking too far. @Piflik is correct, if the slider is moved completely to the right, the shininess value the shader uses is 1.
$$anonymous$$y mistake came from the fact that this value is then internally multiplied by 128, and this value is then used as the specularity exponent in the Blinn-Phong lighting model. But this value is not visible to the user.
Answer by helloiam · Jan 14, 2013 at 09:37 PM
When I do that and I fill for someValue 2f in the Inspector. And I start the game it goes to 128 the max value. Why is that? But it works so thanks.
This is not an answer. Use the comment function, if you have a comment to an answer (or question)
See @Piflik's comment in the other answer. Sorry for the confusion.
Your answer
Follow this Question
Related Questions
get all scripts attached to gameobject 2 Answers
Assign a 'Transform' target to prefab by finding a 'GameObject' 1 Answer
Character moving weirdly 1 Answer
Unity Crashes when C# script with code inside class but outside function is added to a GameObject 1 Answer
Async Calculations in a level 2 Answers