Script has been added to my object but it cannot be found using GetComponent()
This is my code in my Update() function:
if(Input.GetMouseButton(0)){
seePainting();
this.gameObject.GetComponent<Blur>().enabled = true;
}
if(Input.GetMouseButton(1)){
this.gameObject.GetComponent<Blur>().enabled = false;
}
Unity says that that Component cannot be found. My script has been added to the FirstPersonCharacter camera along with the Blur script. What's wrong?
Do you get the error at compile time or run time? Can you show the Blur script?
Compile time. The Script I added is the simple Blur script in the Unity Effect package.
Answer by doublemax · Oct 06, 2016 at 11:39 PM
Add this to your script:
using UnityStandardAssets.ImageEffects;
Thanks it works now. Why isn't it recognize the Blur script?
The class is defined in the UnityStandardAssets.ImageEffects namespace. Without the "using" line, the compiler just didn't know what "Blur" was. It's not that the GetComponent() call didn't find it, that would be a problem that occured at run time, not compile time.
Your answer
Follow this Question
Related Questions
Can someone help me with this camera orbiting script? 0 Answers
How to script a random asset generator> 0 Answers
How can I get all cameras enabled true false states ? 0 Answers
Boolean variable is never true, even if declared true or ticked in the inspector 1 Answer
How to make a ladder script 0 Answers