Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

GetComponent on an image effect reference

Discussion in 'Scripting' started by AxelFaux, Oct 7, 2015.

  1. AxelFaux

    AxelFaux

    Joined:
    May 16, 2014
    Posts:
    2
    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 :(



    Thanks for your help !
     
  2. Ian094

    Ian094

    Joined:
    Jun 20, 2013
    Posts:
    1,548
    Try "LimitMaximum".

    Case sensitive.
     
  3. AngryAnt

    AngryAnt

    Keyboard Operator

    Joined:
    Oct 25, 2005
    Posts:
    3,045
    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.<ContrastStretch> ().limitMaximum ();
     
    StarManta likes this.
  4. AxelFaux

    AxelFaux

    Joined:
    May 16, 2014
    Posts:
    2
    Ok I will know for the next, but I have the same error and also with "LimitMaximum" :/

    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.<ContrastStretch> ().limitMaximum;

    Thank you for your help :)