Accessing property of material with custom shader

Hey guys.
I’m working on a mechanic to highlight objects when they are interactable in a 3D game. For this I’m currently using this shader: http://wiki.unity3d.com/index.php/Silhouette-Outlined_Diffuse

I had the idea that in every frame I would do a Raycast from the center of the screen. If it hits an object with the interactable-script(a script from me) attached to it and it is in range to interact, then I’d display “Interact” on the screen to tell the user that there is an interaction available. This mechanic works until here.
Since I want to “highlight” it a little more I added this shader. Whenever I would display that “Interact Message” thing, I’d like to set the outline width(Property of the shader) to a value to “activate” the outlining. If I’m not in range or the Ray doesn’t hit the object, the outline width is then 0.

I didn’t write the shader and I’m fairly new to shaders. The real question is: How can I manipulate the “Outline width” of this material via script? I tried something with material.SetFloat(“unknownNameOfProperty”, float); I also read on the internet that I have to use activateKeyword(“unknownNameOfProperty”);
For the string that I passed in these functions I tried many things like “Outline width”, “outline width”, “_Outline_Width” and many many more. I just can’t figure out how to do this.

If you guys could help me, I’d be really thankful :slight_smile:
Answers preferebly in C# but JavaScript would be okay I guess. And if you have another, maybe more efficient, method for this problem please tell me :smiley:

Thank you in advance :smiley:

Hello, here is my example code.

using UnityEngine;
using System.Collections;

public class CharacterOnInteraction : MonoBehaviour
{
    public void SetOutLineWidth (float width)
    {
        material.SetFloat ("_Outline", width);
    }
}

What troubles you is the fact that “Outline Width” is the DESCRIPTION of the variable _Outline, and thus calling it doesn’t make any sense. “_Outline” is what should be used.

You may use material.SetFloat (“varName”, value); to change the UNIFORM Variables in your shader. You can also set other variable types such as Color (Official Document Here) and vector and so on. You may simply check the online manual for more information. All relevant info about Material

Please feel free for further questions and I am willing to be of help.

BTW honestly speaking, the shader that you have utilized doesn’t react appropriately with models that have sharp normal direction changes (Such as Cube). Hence I recommend you to take a reference at my solution here.

GL & HF!