- Home /
Trying to change fog when entering a collider trigger!
I am making a 3rd person game.
I have this camera and a capsule collider with "Is Trigger" checked. The collider is in an object tagged "Water". I wrote (more like took pieces of other scripts and Frankensteined) a simple script and attached it to the camera.
This is the script:
public class CameraInWater : MonoBehaviour {
void OnTriggerEnter(Collider other)
{
if (other.gameObject.tag == "Water") {
RenderSettings.fog = true;
RenderSettings.fogColor = new Color (0.35f, 0.55f, 0.6f, 0.2f);
RenderSettings.fogDensity = 0.2f;
}
}
void OnTriggerExit(Collider other)
{
if (other.gameObject.tag == "Water") {
RenderSettings.fog = true;
RenderSettings.fogColor = new Color (0.5f, 0.6f, 0.9f, 1f);
RenderSettings.fogDensity = 0.001f;
}
}
}
Of course, nothing happens. I didn't expect it to work but I cannot see what I'm doing wrong. If anyone is interested here is a video of my game: https://www.youtube.com/watch?v=qRTyDTKX4Zk
As you can see 40 seconds into the video, the fog changes when the camera is below a certain point in the y axis. This is what I want when the camera enters the triggering collision. I also have a lake on top of a mountain in the same scene.. under that water, that's where I want to change the "fog".
I am a huge newbie to scripting, I'm sure what I'm trying to do is either impossible or has a ridiculously simple solution. Sorry!
You want a fog change to trigger when the camera is inside a water volume, but you're also using another method to change the same fog settings when the camera goes below a Y threshold? So, perhaps the other method is overriding this one?
If not, ensure your colliders are property set up to cause these events to trigger.
That's strange I toggled the other script off before and it didn't work, but after reading your post and went and tried again and it does work now. Thanks!
Your answer
Follow this Question
Related Questions
Strange lighting on large-scale objects when using fog in VR 2 Answers
character switching on collision 1 Answer
Global Fog, rotating the camera by itself 0 Answers
How to prevent the animator from changing my rotation? 2 Answers
color Tint camera 5 Answers