New to Unity and trying to get a script that will allow image effects attached to the main camera to be cycled through with button presses.
At the moment I have different effects that are attached to different cameras that I can cycle through(the cameras) but it would be more efficient to have them all on the one camera object so that when I do modifications to the camera, I only have to do it once.
I have looked at the following reference:
Code:
using UnityEngine;
using System.Collections;
public class example : MonoBehaviour {
void Update() {
OtherScript otherScript = GetComponent<OtherScript>();
otherScript.DoSomething();
}
}
but cant seem to work it out.
I have a BloomEffect and a EdgeDetectEffect script that I want to use.
Any advice
If you look at the script they are using namespaces, so you are able to do “using UnitySampleAssets.ImageEffects;” Then you can correctly reference the BloomAndFlares without any extra hastle.
Example:
using UnityEngine;
using System.Collections;
using UnitySampleAssets.ImageEffects;
public class ChangeCamEffects : MonoBehaviour {
public GameObject MainCam;
public void DoStuff() {
MainCam.GetComponent<BloomAndFlares> ().bloomIntensity = 1;
}
}
Hope this helps.
The question is almost 4 years old... And your answer is for Unity 4.6+ which was released a month ago. For that time your answer is wrong. BloomEffect was a JS script, which needed to be put in a firstpass folder for it to work.
I had the issue the other day, and there was no up-to-date answer. I'm sure this would help people having the issue now, giving comments like yours won't =)
Thank you. I was trying for several hours yesterday trying to get access to my shader scripts, and simply adding the namespace like you suggested did exactly what I wanted.
I had a similar problem. The first thing you need to do is move all the Image Effects scripts that you use to \Assets\Plugins folder (make one if you don’t have it already). That way the .js files can be accessed from the .cs files (for instance, c# won’t recognize BloomAndLensFlares as a class until you do and so you can’t pass it as a component to the OtherScript variable).
After you’ve done that, all you have to do is indeed store BloomAndLensFlares (or any other image effect for that matter) in a variable (preferably cache it at the Start() or Awake() methods for more efficient code)and later change the ‘enabled’ property of the component as needed.
For example:
using UnityEngine;
using System.Collections;
using Assets.Scripts;
public class ToggleBloom : MonoBehaviour
{
private BloomAndLensFlares _bloomToggle;
void Start()
{
_bloomToggle = transform.GetComponent("BloomAndLensFlares") as BloomAndLensFlares;
}
// Update is called once per frame
void Update ()
{
if(Input.GetKeyDown("space"))
{
_bloomToggle.enabled = !_bloomToggle.enabled;
}
}
}
Now you’ll probably want to store the effects in an array and iterate over them as you press the button, but that’s the general idea.
Cheers, Works a treat. Yeah, I admit I was lost with why it wouldnt recognize the c# classes. Using that class you created, am I correct in that I can access all variables/properties of the BloomAndLensFlare class? So to use a button press to change the intensity would be something like: if(Input.GetKeyDown("I")) { _bloomToggle.bloomIntensity++; } Thanks Again
The question is almost 4 years old... And your answer is for Unity 4.6+ which was released a month ago. For that time your answer is wrong. BloomEffect was a JS script, which needed to be put in a firstpass folder for it to work.
– EvilTakI had the issue the other day, and there was no up-to-date answer. I'm sure this would help people having the issue now, giving comments like yours won't =)
– mattcsczThank you. I was trying for several hours yesterday trying to get access to my shader scripts, and simply adding the namespace like you suggested did exactly what I wanted.
– YK9I can't seem to access the Effects like that :(
– admasto95