- Home /
Accessing C# scripts from other objects
I'm sure this is asked a lot, but I have looked around but nothing seems to help fix this. I have a script that is going to activate image effects on a camera when the camera goes below a certain y value. I have linked the camera GameObject through the script and that seems to work fine, however, when I tried to link the three image effects, I get errors for each one stating that "The type or namespace name could not be found"
Here is the script:
using UnityEngine;
using System.Collections;
public class WaterEffect : MonoBehaviour {
GameObject WaterTop;
GameObject WaterBot;
bool UnderWater;
GameObject PlayerCamera;
private Blur BlurEffect;
private ColorCorrectionCurves ColCorEffect;
private GlobalFog GloFogEffect;
// Use this for initialization
void Start ()
{
PlayerCamera = GameObject.Find("FirstPersonCharacter");
BlurEffect = PlayerCamera.GetComponent<Blur>();
ColCorEffect = PlayerCamera.GetComponent<ColorCorrectionCurves>();
GloFogEffect = PlayerCamera.GetComponent<GlobalFog>();
}
// Update is called once per frame
void Update ()
{
if(PlayerCamera.transform.position.y < gameObject.transform.position.y){
UnderWater = true;
BlurEffect.active = true;
ColCorEffect.active = true;
GloFogEffect.active = true;
} else if(PlayerCamera.transform.position.y > gameObject.transform.position.y){
UnderWater = false;
BlurEffect.active = false;
ColCorEffect.active = false;
GloFogEffect.active = false;
}
}
}
Answer by sprawww · Mar 25, 2015 at 10:44 PM
You're missing the namespace for the effects. Edit the very top of your script with this:
using UnityEngine;
using System.Collections;
using UnityStandardAssets.ImageEffects;
This worked for the blur and color correction effects but I still seem to get the same error for the global fog effect
Just checked, it's true. GlobalFog isn't public. You may open GlobalFog.cs and change
class GlobalFog : PostEffectsBase
to
public class GlobalFog : PostEffectsBase
I want to tell you that this is just a quickfix and not futureproof :)
Your answer
Follow this Question
Related Questions
error CS0131: The left-hand side of an assignment must be a variable, a property or an indexer 3 Answers
Displaying a static variable from another script with OnGUI 1 Answer
Creating .txt file error 1 Answer
Why won't my script load? 1 Answer
"Object reference not set to an instance of an object" problem 1 Answer