Cant Enable And Disable Scripts
So im trying to toggle a script on my scene camera how ever im getting an error with the line " var bloom = mainMenuCamera.GetComponent<"Bloom">();" its telling me that ")" is unexpected. Cant think why. Any help would be fantastic.
public class VideoController : MonoBehaviour {
[Header("Video Settings:")]
public bool isBloomOn;
[Header("Toggle Text:")]
public Text bloomToggleText;
[Header("Cameras:")]
public GameObject mainMenuCamera;
void Start () {
if (!PlayerPrefs.HasKey ("isBloom")) {
PlayerPrefs.SetInt ("isBloom", 1);
var bloom = mainMenuCamera.GetComponent<"Bloom">();
}
}
void FixedUpdate () {
if (PlayerPrefs.GetInt ("isBloom") == 1) {
bloomToggleText.text = "ON";
isBloomOn = true;
} else {
isBloomOn = false;
bloomToggleText.text = "OFF";
}
}
public void ToggleBloom () {
if (PlayerPrefs.GetInt ("isBloom") == 1) {
PlayerPrefs.SetInt ("isBloom", 0);
} else {
PlayerPrefs.SetInt ("isBloom", 1);
}
}
}
Answer by AurimasBlazulionis · Jan 18, 2017 at 02:26 PM
The type when getting the component must not be in quotes. The line should look like this:
var bloom = mainMenuCamera.GetComponent();
However, having this variable makes no sense since it is defined in Start and will not be available anywhere else. Have a variable outside the functions: public Bloom bloom;
. If you can assign it, do it, because GetComponent is not good on performance. Otherwise, remove var
from the line in start.
That still does not work, im trying to reference a script from the main camera called "Bloom" but i cant seem to get it to work.
Open the bloom script and copy what is inside namespace
, then paste it at the top of your script like this: using <namespace>;
.
this is the namespace of the Bloom script "namespace UnityStandardAssets.CinematicEffects"
so how would i make it work? main$$anonymous$$enuCamera.GetComponent("Bloom").enabled; <-- does not work still
sorry for the hassle, im kinda new to program$$anonymous$$g (if you haven't realized lol)
Your answer
![](https://koobas.hobune.stream/wayback/20220612105056im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
ReEnable mouse(movement,selection,etc) after loading game menu 1 Answer
Reference a script on a gameobject that is disabled in scene 0 Answers
Enable/Disable other gameobject's scripts Unity 5 0 Answers
Timeline animation frozen after being disabled 1 Answer
How to enable only one script (shared by multiple gameobjects) at a time/click ? 1 Answer