- Home /
C# GetComponent()... Not finding script problem.
I'm pretty definite that the code is correct in the way it should be used, however in this specific problem, the Blur script which is an Image Effect (and is in the correct location of Standard Assets\ImageEffects\Scripts\Blur.cs), doesn't want to be seen almost and returns with an error telling me that "The name 'Blur' does not exist in the current context".
I'm wondering if this is due to the script loading after the GameMenuPause.cs script runs itself therefore skipping it or the otherway around, causing the error of CS0103. Either that or my code is buggered somewhere. Note, this is in the newest update of Unity5 5.0.1f1 (If it is a bug with the engine itself somehow). Help would be much appreciated, thanks in advance...
The lines of errors are 24 and 29 where gameObject.GetComponent() is used.
using UnityEngine;
using System.Collections;
public class GameMenuPause : MonoBehaviour {
public bool paused;
public Camera effectCamera;
void Start () {
Screen.lockCursor = true;
Time.timeScale = 1f;
}
void Update () {
if(Input.GetButtonDown("Pause")){
if(paused){
paused = false;
}else{
paused = true;
}
}
if(!paused){
effectCamera.GetComponent<Blur>().enabled = false;
Screen.lockCursor = true;
Time.timeScale = 1f;
AudioListener.pause = false;
}else{
effectCamera.GetComponent<Blur>().enabled = true; // Would have the enabled function to turn it on and off.
Screen.lockCursor = false;
Time.timeScale = 0f;
AudioListener.pause = true;
}
}
}
Kind Regards,
J. Tobar-Chapman
Answer by tanoshimi · May 05, 2015 at 10:54 AM
Image effects are defined in the UnityStandardAssets.ImageEffects namespace, so you'll need to include a reference to that at the top of your code:
using UnityStandardAssets.ImageEffects;
A legend is what you are, thanks for that mate. Works as it should.
Your answer
Follow this Question
Related Questions
Unexpected token ) when dealing with getcomponent 1 Answer
AddComponent can't find script name MouseOrbit? 1 Answer
Null Reference Exception Help 1 Answer
Unknown identifier when turning off SSAO through a JS script 1 Answer
Need to Access GlowEffect From Script and Add To "Intensity" Parameter 0 Answers