Search Unity

  1. Calling all beginners! Join the FPS Beginners Mods Challenge until December 13.
    Dismiss Notice
  2. It's Cyber Week at the Asset Store!
    Dismiss Notice

Enable / disable image effects

Discussion in 'Editor & General Support' started by pandigital, Mar 21, 2010.

  1. pandigital

    pandigital

    Joined:
    Mar 20, 2009
    Posts:
    15
    Can you please tell me how to enable a disabled image effect using a java script attached to the same camera.
    A full example code would be useful.

    many thanks
     
  2. Discord

    Discord

    Joined:
    Mar 19, 2009
    Posts:
    1,002
    My image effect is applied to my camera which is a child of my fps controller, so on my fps controller I do something like:
    Code (csharp):
    1. blur = GetComponentInChildren(MotionBlur);
    2. if(Mathf.Abs(rigidbody.velocity.x) > speedToBlur || Mathf.Abs(rigidbody.velocity.y) > speedToBlur || Mathf.Abs(rigidbody.velocity.z) > speedToBlur)
    3.         blur.enabled = true;
    4.     else
    5.         blur.enabled = false;
    6.  
    7.    }
     
  3. pandigital

    pandigital

    Joined:
    Mar 20, 2009
    Posts:
    15
    I have
    Code (csharp):
    1. color_script = GetComponent ("ColorCorrection");
    2.         color_script.enabled=false;
    attached to the Main Camera in the FPC, the same camera that the effect component is attached to - but nothing happens and no error is reported in the console.
     
  4. Discord

    Discord

    Joined:
    Mar 19, 2009
    Posts:
    1,002
    Don't put quotes around ColorCorrection.
     
  5. pandigital

    pandigital

    Joined:
    Mar 20, 2009
    Posts:
    15
    No difference

    In your example what have you declared blur as?
     
  6. DocSWAB

    DocSWAB

    Joined:
    Aug 28, 2006
    Posts:
    615
    This works in Unity 3.1 using pragma strict:

    var correx:ColorCorrectionCurves = Camera.main.GetComponent(ColorCorrectionCurves) as ColorCorrectionCurves;
    correx.enabled = flag;