GetComponent on an image effect reference

Hello there ! Firstly I’m french, then sorry for my mediocre english.

So I need your help for this problem :

I’m using an image effect reference, the “Contrast Stretch Effect”, as you see on this link http://docs.unity3d.com/Manual/script-ContrastStretch.html

I would like to change in game, with help of my script, the property “limitMaximum”.
If I try to do this, it’s to have a linear contrast modification which will be darken.

In fact this property will be dependent of the volume of an object to my scene, cause why I want to call this property / float.

To show you my script :

private var contrast : float; //float which is using on the component ContrastStrech.limitMaximum
private var newValue : float; //The volume of audioSource of an other object

function Start () {

contrast = cameraEffect.GetComponent(“ContrastStretch”).limitMaximum();
}

function Update () {

contrast = newValue;
}

But the console say me “limitMaximum” is not a member of ‘UnityEngine.Component’.
How can I resolve this please ? I don’t find the solution :frowning:

Thanks for your help !

Try “LimitMaximum”.

Case sensitive.

I would generally advise against using the GetComponent variant taking a string parameter. It is opening you up to typos and the lack of compile time checking will further not help you if you ever decide to rename the component.

This is also why the call returns a regular Component reference, as the type of the component is not known at compile time. And the Component type of-course does not define the limitMaximum function.

Your preferred alternative is the generic variant of GetComponent. For JS the syntax is as follows: cameraEffect.GetComponent. ().limitMaximum ();

1 Like

Ok I will know for the next, but I have the same error and also with “LimitMaximum” :confused:

Then I have remove the script into the Standard Asset folder cause he is wasn’t, and I had this error which said me I can’t use float etc etc when I use your syntax.

So I just modify the end of the syntax : without parenthesis “()”

So now this work correctly with this syntax :
cameraEffect.GetComponent. ().limitMaximum;

Thank you for your help :slight_smile: