- Home /
Trigger Camera Effect
Hi, I have a first person player in my game. On the player's camera there is a motion blur script which is disabled. I want when my player Enters a trigger effect enables.
I was looking on google and trying to figure it out but everything was wrong. Plss help me out with code (C#)!
this code doesn't woork:
using UnityEngine;
using System.Collections;
public class EnableComponents : MonoBehaviour
{
private Script blur;
void Start ()
{
blur= GetComponent<MotionBlur>();
}
void Update ()
{
if(Input.GetKeyUp(KeyCode.Space))
{
blur.enabled = !blur.enabled;
}
}
}
No, i tried everything. A lot of scripts but they didn't work. GetComponent doesnt recognize $$anonymous$$otion Blur <-- error, everytime!
Answer by hoekkii · Jun 21, 2015 at 03:26 PM
Add this on line 3:
using UnityStandardAssets.ImageEffects;
so the script would look like this:
using UnityEngine;
using System.Collections;
using UnityStandardAssets.ImageEffects;
[RequireComponent(typeof(MotionBlur))]
public class EnableComponents : MonoBehaviour
{
private MotionBlur motionBlur = null;
public MotionBlur MotionBlur
{
get
{
if (motionBlur == null)
{
motionBlur = GetComponent<MotionBlur>();
}
return motionBlur;
}
}
void Update()
{
if (Input.GetKeyUp(KeyCode.Space))
{
MotionBlur.enabled = !MotionBlur.enabled;
}
}
}
And for the trigger, use: "http://docs.unity3d.com/ScriptReference/Collider.OnTriggerEnter.html" and "http://docs.unity3d.com/ScriptReference/MonoBehaviour.OnTriggerExit.html"
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Enabeling components 1 Answer
Can I create a blinking effect on my first person camera with vignette? 0 Answers
Active camera on Start 1 Answer
Aimming zoom problem 0 Answers