Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by shadowpuppet · Nov 28, 2017 at 05:37 PM · floatincreaseambient light

gradual ambient light intensity change

I am in a dark tunnel so no light except low ambient. As I come out of the tunnel I want to increase the intensity - I have an empty gameobject at the end of the tunnel and when the player gets within a certain distance I get the brightness to increase but how do I do this over time? Or rather, as the player gets closer the brightness increases and further the brightness decreases. The code below just acts light a light switch rather than gradual

 using UnityEngine;
 using System.Collections;
 
 public class ambientIncrease : MonoBehaviour {
     public float liteChange = 5f;
     public Transform Player;
 
     void Start () {
     
     }
 
     void Update () {
         if (Vector3.Distance (transform.position, Player.position) <= liteChange) {
             RenderSettings.ambientLight = new Color(.5f, .5f, .5f, 255);
 
         }
     }
 }
Comment
Add comment
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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by tonibm1999 · Nov 28, 2017 at 07:44 PM

You're just setting the ambient light to a certain value, which is constant.

You need to get a variable value for light color depending on distance.

Comment
Add comment · Show 1 · Share
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 shadowpuppet · Nov 28, 2017 at 08:32 PM 0
Share

I know what it is doing and why...I figured out how to do your observation and vary the value based on distance but now need to clamp the values. I guess I could make another script that enables and disables this script if the player goes to far from target

avatar image
0

Answer by shadowpuppet · Nov 28, 2017 at 08:10 PM

This works for changing the brightness...but I am now having trouble with limits. I don't want it to be brighter than .5 or darker than .25. right now it is getting too dark or bright but I can't seem to figure out the syntax for an if statement

 void Update () {
         
         distance = Mathf.Round(Vector3.Distance(gameObject.transform.position, Target.transform.position))*.04f;
         
         
             RenderSettings.ambientLight = new Color(.5f, .5f, .5f, 255)* distance;
             }
         }

// tried adding these two if conditions but get errors.how do I clamp that range?

 if(RenderSettings.ambientLight.Color <= ( .5f, .5f, .5f, 255)) {
                 if(RenderSettings.ambientLight.Color >= ( 2.5f, 2.5f, 2.5f, 255)) {
 
   
Comment
Add comment · Show 1 · Share
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 shadowpuppet · Nov 28, 2017 at 08:43 PM 0
Share

I cheezed a solution by making a short triggerzone in the tunnel exit so that as long as I am in that trigger zone the lighting will go up or down as I move toward or away from exit. moving in and out several times eventually messes up the clamping I want a little bit ( like 12 times back and forth) but realistically no player would do that as there is nothing to go back for...it's the start of a new level

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

120 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How can I change the value of a Float smoothly? 2 Answers

Decreasing a value over time, called by InvokeRepeating 0 Answers

Mecanim: How to set the range for a float field so that shortest distance is interpolated to next key frame? 1 Answer

Can you do float + float 1 Answer

i am new at unity, how to add location in float values in gui ? in following i want to add location of ** x (25.78) and y (25.98) ** but there is an error, 1 Answer


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