- Home /
How to disable blurOptimized from another script
Hi I am very new to C# and have been working on this for a few days now. Basically what i'm trying to achieve is to play my intro animation on start(works fine) disable my controls using a coroutine for 5 seconds(works fine) and now at the same time that the controls enable again, I would like my "BlurOptimized" image effect to also be turned off.
I have two scripts - one that handles the disabling of controls, intro and blur "disable.cs" and one "disableblur.cs" script
disable.cs is attached to the unity 5 FPScontroller object and the disableblur.cs is attached to the firstpersoncharacter object that is inside FPScontroller as this is where the image effect is added to cause the blur.
my code for disable is
using UnityEngine;
using System.Collections;
using UnityStandardAssets.Characters.FirstPerson;
using UnityStandardAssets.ImageEffects;
public class disable : MonoBehaviour {
public float waitSeconds;
// Use this for initialization
void Start () {
disableblur dblur = GetComponent<disableblur> ();
GetComponent<Animation> ().Play ("intro");
StartCoroutine (introSeq ());
}
IEnumerator introSeq()
{
//This is a coroutine
GetComponent<FirstPersonController> ().enabled = false;
yield return new WaitForSeconds(waitSeconds); //Wait five seconds
GetComponent<FirstPersonController> ().enabled = true;
gameObject.GetComponent<disableblur>().enabled = true;
}
// Update is called once per frame
void Update () {
}
}
and my code for disableblur is:
using UnityEngine;
using System.Collections;
using UnityStandardAssets.Characters.FirstPerson;
using UnityStandardAssets.ImageEffects;
public class disableblur : MonoBehaviour {
// Use this for initialization
void Start () {
GetComponent<BlurOptimized> ().enabled = false;
}
// Update is called once per frame
void Update () {
}
}
the error i am getting is on disable.cs is
NullReferenceException: Object reference not set to an instance of an object disable+c__Iterator0.MoveNext () (at Assets/disable.cs:21)
line 21 is where i call the script disableblur.cs to be enabled.
Any help is much appreciated
I solved this by adding a new coroutine to disableblur.cs and doing exactly the same thing as I did in disable.cs - thus allowing me to access the blurOptimized component directly ins$$anonymous$$d of trying to access it from FPScontroller. if anyone knows why i couldnt access it from there please post and I will accept the answer
Your answer
![](https://koobas.hobune.stream/wayback/20220612044431im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
G-Buffers don't exist... 0 Answers
MeshCombineUtility problem after upgrade to Unity 5? 2 Answers
Reference DLL's 1 Answer