- Home /
how enable / disable blur effect using script attached to another game object
this script compile but dont work in the game so when i press F the blur effect dontt works
i tryed to disable in the start method it works bur when i press F it dont works
if someone can help me solving this !!!!!!!!!
using UnityEngine; using UnityEngine.UI; using UnityStandardAssets.ImageEffects;
public class read_sheet : MonoBehaviour {
public Image photo;
public Camera fpscam;
public float range =2;
public Blur blureffect;
void Start()
{
//fpscam.GetComponents<Blur>() ;
// blureffect.enabled = false;
}
void Update () {
RaycastHit hitinfo;
if (Physics.Raycast (fpscam.transform.position, fpscam.transform.forward, out hitinfo, range))
{
if ((hitinfo.transform.name == "sheet1"))
{
if (Input.GetKeyDown(KeyCode.F)) {
photo.gameObject.SetActive(true);
blureffect.enabled = true;
}
}
else
photo.gameObject.SetActive(false);
blureffect.enabled = false;
}
} }
And you've made sure when you are hitting F that you are within a certain distance from and looking at an object named "sheet1" with a collider attached and not in the ignoreraycast layer?
Try to debug this, f.e.
if ((hitinfo.transform.name == "sheet1"))
{
**print("Sheet1 reached");**
if (Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.F)) {
photo.gameObject.SetActive(true);
blureffect.enabled = true;
}
}
Answer by Garazbolg · Jun 07, 2017 at 10:54 AM
You're just missing some brackets :
using UnityEngine; using UnityEngine.UI; using UnityStandardAssets.ImageEffects;
public class read_sheet : MonoBehaviour {
public Image photo;
public Camera fpscam;
public float range =2;
public Blur blureffect;
void Start()
{
blureffect = fpscam.GetComponents<Blur>() ;
blureffect.enabled = false;
}
void Update () {
RaycastHit hitinfo;
if (Physics.Raycast (fpscam.transform.position, fpscam.transform.forward, out hitinfo, range))
{
if ((hitinfo.transform.name == "sheet1"))
{
if (Input.GetKeyDown(KeyCode.F)) {
photo.gameObject.SetActive(true);
blureffect.enabled = true;
}
}
else
{ // There
photo.gameObject.SetActive(false);
blureffect.enabled = false;
} // And there
}
} }
Because you didn't have those, your script would always disable your blur effect at the end of each Update.
thank you so much sometimes little things turn me crazy ^ ^
Don't worry we all have are moments when we are so deep that we can't see past our nose. ^^
Your answer
Follow this Question
Related Questions
Enable/Disable Game Object With GUI Button 1 Answer
Enabling loop and disabling loop 1 Answer
Enable/Disable a Static object 1 Answer
image not enabling 0 Answers
Gui.Enable transperancy 4 Answers