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 CerebralStatic · Mar 20, 2021 at 05:38 PM · scripting problemfloatpoint light

How to change a point light intensity with an updating float

For reference, speedMultiplier = 200 and the intensity fo the point light is 5000. (lux) My engine object has a point light child and this script. Speed Multiplier is the speed of another object, which I want to use to control the light intensity. multiplierUpdate defines and displays the float values, while UpdateValues overrides the light.intensity. When I start the game, the point light disappears from the inspector, and lightIntensity says 318 for some reason. When I delete UpdateValues to see what happens, the point light stays in the inspector when I start, but lightIntensity still says 318, clearly referring to something else.

 public class Engine_Controller : MonoBehaviour
 {
     public Free_Roam freeRoam;
     public Light lightObject;
     public float lightIntensity;
     public float speedMultiplier;
     
 
     public void Update()
     {
         multiplierUpdate();
         UpdateValues();
     }
 
     public void multiplierUpdate()
     {
         lightIntensity = lightObject.intensity;
         speedMultiplier = freeRoam.speed;
     }
     
     void UpdateValues()
     {
         lightObject = gameObject.GetComponent<Light>();
         lightObject.intensity = lightIntensity * speedMultiplier;
     }
     
 }
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by toficofi · Mar 21, 2021 at 01:04 PM

You are setting lightIntensity = lightObject.intensity and then assigning it back to lightObject.intensity = lightIntensity * speedMultiplier. This means that on the next update, you are doing lightIntensity = lightObject.intensity again which gives you the already multiplied value, and you multiply it again, and so on.


You probably just want to remove lightIntensity = lightObject.intensity and instead do lightObject.intensity = lightObject.intensity * speedMultiplier.

Comment
Add comment · Show 2 · 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 toficofi · Mar 21, 2021 at 01:06 PM 0
Share

also - you say "My engine object has a point light child and this script", but gameObject.GetComponent<Light> doesn't look for children, it looks for components attached to that game object.

avatar image CerebralStatic · Mar 21, 2021 at 07:24 PM 0
Share

Yup! I understand the disconnect now, a very simple misreading of some basic steps. I love learning this stuff but the price is a lot of hit and miss, lol. Anyway, thanks for your input! for reference, it looks like this now:

 public class Engine_Controller : MonoBehaviour
 {
     public Free_Roam freeRoam;
     public Light lightObject;
     public float lightIntensity;
     public float speedMultiplier;
 
     public void Start()
     {
         speedMultiplier = freeRoam.speed;
         lightIntensity = lightObject.intensity;
     }
 
     public void Update()
     {
         speedMultiplier = freeRoam.speed;
         UpdateValues();
     }
 
     void UpdateValues()
     {
         lightObject.intensity = lightIntensity * (speedMultiplier / 100);
     }
 }

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

207 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 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 to get float value from other script? 2 Answers

Modify a vector 2 in pbr shader using c# 1 Answer

How to synrchonize two floats from different scripts? 1 Answer

How to make an object rotate on randon axes when spawned? 2 Answers

why the debree timer float not work 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