Search Unity

Activate/Deactivate Image Effect on "MouseDown"

Discussion in 'Scripting' started by GLucasDev2, Feb 13, 2014.

  1. GLucasDev2

    GLucasDev2

    Joined:
    Jul 24, 2013
    Posts:
    77
    Code (csharp):
    1.  public var myCamera : Camera;
    2.  private var myEffect : PP_Negative;
    3.  
    4.     function Start ()      
    5.  
    6.         {
    7.  
    8.             myEffect = GetComponent(PP_Negative);
    9.      
    10.         }
    11.  
    12.  
    13.         function Update ()
    14.  
    15.         {
    16.  
    17.  
    18.             if(Input.GetMouseButtonDown(0))
    19.  
    20.             {
    21.  
    22.              myEffect.enabled = !myEffect.enabled;
    23.  
    24.             }
    25.  
    26.         }
    I jsut need to know how id go about plugging in the "public var myCamera" into the rest so i can use this on a gui button instead of a keypress method i had previously.

    I already changed the "if(Input.GetKeyDown(E))" to "if(Input.GetMouseButtonDown(0))", now i just need to know where to put the var Camera.

    Thank you in advance!
     
  2. Prophet54

    Prophet54

    Joined:
    Apr 18, 2013
    Posts:
    8
    public var myCamera : Camera;
    //private var myEffect : PP_Negative;

    function Start ()

    {

    //myEffect = GetComponent(PP_Negative);

    }





    function OnGUI () {
    if (GUI.Button (Rect (10,10,150,100), "I am a button")){
    myCamera.GetComponent(PP_Negative).enabled = false;
    print ("You clicked the button!");
    }
    }