- Home /
Enable/Disable shader on script
So, I'm working on action horror game. There is an enemy in this game. I want when the enemy attack, (this shader) will be enabled on camera.
However I am unsure of how to disable/enable the shader in the camera, anyone has any idea how?
What do you mean by 'enable shader on script'? Shaders are on materials. What do you mean by 'on camera'?
I see a lot of games when you being hitted by something, they will use this special effects on camera and I'm pretty sure they use shader.
Answer by Cains · Nov 10, 2013 at 06:59 AM
Understand that a shader is sort of like a template for a material, telling the camera how to actually "see" the material. Because shaders are merely templates, you can't actually enable or disable them (you shouldn't even need to alter them during runtime).
However the material, which is the instance of a shader given to the GameObject, can be altered to suit your needs. You can switch the shader your material is using with Shader.Find, you can actually enable/disable the renderer displaying your GameObject like shown here, or you can set the attributes of the material using renderer.material.
If you have any questions feel free to ask and if you want to know what to do in your specific situation then elaborate more on what you want done in your game like the actual effect you're trying to create. An example of a game using the effect would be very helpful.
Answer by tanoshimi · Nov 10, 2013 at 07:35 AM
I suspect from your description that you may be thinking of an image effect rather than a shader. They are similar in many respects, but rather than change how an individual material on an object is drawn to the screen, an image effect alters the entire image rendered by a camera.
Image effects can be used for things like adding dirt to a lens, adding blurs and depth of field effects etc. However, note that they are only available in Unity Pro.
Either that, or you might be able to create the effect you want by placing a transparent plane or GUITexture in front of the camera, and applying effects to that. For an example, see @aldonaletto's answer in http://answers.unity3d.com/questions/189677/blood-damage-like-call-of-duty.html
Your answer
Follow this Question
Related Questions
Fade an object in and out 0 Answers
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Enable/Disable AI script 1 Answer
Help With Disabling/Enabling single GameObject 1 Answer
[Solved]cant disable/enable scripts 1 Answer