- Home /
Unable to disable a C# script with a JS Script
I can't seem to disable "DepthOfField.cs" with my "Bino.js" script, this is the code used: #pragma strict
var zoom : int = 20;
var glassesVision : int = 80;
var normal : int = 90;
var smooth : float = 5;
private var isZoomed = false;
//Glasses functions
var GlassesImageOn = false;
var GlassesImage : GameObject;
var dof : DepthOfField;
function Start () {
GlassesImage.SetActive (false);
dof = gameObject.GetComponent("DepthOfField");
}
function Update ()
{
if(Input.GetMouseButtonDown(2))
{
isZoomed = !isZoomed;
}
if(isZoomed == true)
{
GetComponent.<Camera>().fieldOfView = Mathf.Lerp(GetComponent.<Camera>().fieldOfView, zoom, Time.deltaTime * smooth);
}
else
{
GetComponent.<Camera>().fieldOfView = Mathf.Lerp(GetComponent.<Camera>().fieldOfView, normal, Time.deltaTime * smooth);
}
if(Input.GetKeyDown("g")){
GlassesImageOn = !GlassesImageOn;
}
if(GlassesImageOn == true){
GlassesImage.SetActive (true);
dof.SetActive (false);
GetComponent.<Camera>().fieldOfView = Mathf.Lerp(GetComponent.<Camera>().fieldOfView, glassesVision, Time.deltaTime * smooth);
}else{
GlassesImage.SetActive (false);
dof.SetActive (true);
GetComponent.<Camera>().fieldOfView = Mathf.Lerp(GetComponent.<Camera>().fieldOfView, normal, Time.deltaTime * smooth);
}
}
I get this error when i try to run it: Assets/Bino.js(14,11): BCE0018: The name 'DepthOfField' does not denote a valid type ('not found'). Did you mean 'UnityStandardAssets.ImageEffects.DepthOfField'?
When i search the forums and questions/answers and none of them suit unity 5, so i'm stuck trying to figure this out.
Answer by AurimasBlazulionis · Dec 20, 2016 at 08:49 AM
It says what you need to do. Instead of DepthOfField
, define the variable as UnityStandardAssets.ImageEffects.DepthOfField
type. Alternatively, you can add import UnityStandardAssets.ImageEffects;
at the top of the script.
Answer by UnityCoach · Dec 20, 2016 at 11:06 AM
DepthOfField is component, not a GameObject. Use .enabled = false instead of .SetActive(false).
Your answer
![](https://koobas.hobune.stream/wayback/20220612103028im_/https://answers.unity.com/themes/thub/images/avi.jpg)