Trying to acces a parameter of a script at runtime

Hi, community,

i have this piece of code for activating the edge detection on my camera at runtime
what i want to add is a toggle on the"Edges only" value wich i need it to be one most of time
ans sometimes " with a keycode" be 0.5

i’m a code newby so i dont know how to access a particular attribute in a script sith a script
i may guess it is something like but can’t figure it out

Camera.main.GetComponent<UnityStandardAssets.ImageEffects.EdgeDetection.EdgesOnly>
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class EdgeDetectionToogle : MonoBehaviour {

    private bool isActive;
    public KeyCode toggleKey = KeyCode.Space;
    // Use this for initialization
    void Start () {
        // Get script Edge Detection in variable
        var script = Camera.main.GetComponent<UnityStandardAssets.ImageEffects.EdgeDetection>();
        // Desactivate script Edge Detection
        script.enabled = false;
        isActive = false;

    }
   
    // Update is called once per frame
    void Update () {
        // Get script Edge Detection in variable
        var script = Camera.main.GetComponent<UnityStandardAssets.ImageEffects.EdgeDetection>();
        if(Input.GetKeyDown(toggleKey))
        {
            // if script Edge Detection is desactivated -> activate
            if (!isActive)
            {
                script.enabled = true;
                isActive = true;
            }
            // if script is activated -> desactivate
            else
            {
                script.enabled = false;
                isActive = false;
            }
        }

    }
}

help will be greatly appreciate :slight_smile:

best regards

Jex

You do it like so:

Camera.main.GetComponent<ScriptName>().variableName

Works fine thank you !