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 /
avatar image
0
Question by T-yacine · Nov 01, 2018 at 02:17 PM · gamma correction

Manage gamma with a slider in a 2D game

Hello everyone;

I 'm working on 2D game in Unity and I' m wondering how we can manage brightness with a slider which is in the option menu of my game. I wanted to know what are the steps to solve this problem.

Regards

t-yacine

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 Vega4Life · Nov 01, 2018 at 02:47 PM

You could try changing RenderSettings.ambientlight. Have a slider from 0 to 1. Then create a new color with that value and apply it. i.e RenderSettings.ambientlight = new Color(sliderValue, sliderValue, sliderValue, 1.0f);

Comment
Add comment · Show 3 · 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 T-yacine · Nov 01, 2018 at 04:07 PM 0
Share

This what I did but it doesn't seems to work (I didn't create a new color). First, i wrote this code : using System.Collections; using System.Collections.Generic; using UnityEngine;

public class Brightness : $$anonymous$$onoBehaviour { float rgbValue = 0.5f;

 public void onGUI()
 {
     rgbValue = GUI.HorizontalSlider(new Rect(Screen.width / 2 - 50, 90, 100, 90), rgbValue, 0f, 1.0f);
     RenderSettings.ambientLight = new Color(rgbValue, rgbValue, rgbValue, 1);
 }

} I add this component to the directionnal light. However, when I want to apply this funtion to the slider (the slider is in the option menu) in the "on value changed ", I can't find the function i'v coded. So I can't try if my code is correct. Could give a solution to solve my problem.

Regards.

t-yacine

avatar image Vega4Life T-yacine · Nov 01, 2018 at 04:28 PM 0
Share

At a quick glance you have onGUI(), it's actually OnGUI().

I would just add a GameObject -> UI -> Slider (makes it easier than using OnGUI() Once you have that, whatever script you are using, just create a function of:

 public void OnSliderChange(UnityEngine.UI.Slider slider)
 {
     RenderSettings.ambientLight = new Color(slider.value, slider.value, slider.value, 1.0f);
 }

Then link the script you are using, and the function call to the On Value Changed. Also, link the Slider component to send across.

avatar image T-yacine Vega4Life · Nov 02, 2018 at 11:09 AM 0
Share

Hello,

I've tried your solution but it doesn't work, I can attach my script to the slider. I've added my script to my canvas first, then i've tried with the directional light of my menu and finally with the panel, but it doesn't work. N.B : there is no directional light in the game himself but only in the menu.

Regards

t-yacine

avatar image
0

Answer by T-yacine · Nov 01, 2018 at 04:16 PM

This what I did but it doesn't seems to work. First, i wrote this code : using System.Collections; using System.Collections.Generic; using UnityEngine;

public class Brightness : MonoBehaviour { float rgbValue = 0.5f;

public void onGUI() { rgbValue = GUI.HorizontalSlider(new Rect(Screen.width / 2 - 50, 90, 100, 90), rgbValue, 0f, 1.0f); RenderSettings.ambientLight = new Color(rgbValue, rgbValue, rgbValue, 1); } } I add this component to the directionnal light. However, when I want to apply this funtion to the slider (the slider is in the option menu) in the "on value changed ", I can't find the function i'v coded. So I can't try if my code is correct. Could give a solution to solve my problem.

Regards.

t-yacine

Comment
Add comment · 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

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

94 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

Related Questions

Image effect "Color Correction Curves" doesn't work correctly with Linear Space rendering ; how to fix that ? 1 Answer

Why do my linear textures look different in the editor than in the mobile build? 0 Answers

Linear color space - linear or gamma corrected framebuffer? 0 Answers

Using UI textues authored in Gamma space in Linear mode 3 Answers

Combining gamma calibration and tone mapping 0 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