Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Spram · May 04, 2015 at 12:11 PM · cameracolliderwaterfog

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!

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image AlwaysSunny · May 03, 2015 at 08:56 PM 1
Share

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.

avatar image Spram · May 04, 2015 at 01:25 AM 0
Share

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!

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges