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 deano_0707 · Sep 01, 2012 at 06:46 AM · lightintensity

Light Draining Script

Hi, I have attempted to write a code that will drain the battery of the torch (it is just a normal point light) and there is no errors, it is just not doing anything, so what is wrong with this script?

 var LightIsOff : System.Boolean;
 var Recharge : int = 0;
 var LightIntensity : int;
 
 function update(){
     LightIntensity = light.intensity;
     CheckLight();
     if(LightIsOff == false){
         light.intensity -= 0.001;
     }
     
     if(LightIsOff == true){
         if(Recharge == 1.5){
             
         }else{
         Recharge += 0.001;
         }
         }
     
     if(Input.GetMouseButtonDown(2) && LightIsOff == false){
         light.intensity = 0;
     }
     
     if(Input.GetMouseButtonDown(2) && LightIsOff == true){
         light.intensity = Recharge;
     }
 }
 
 function CheckLight(){
     if(light.intensity == 0){
         LightIsOff = true;
     }else{
         LightIsOff = false;
     }
 }

Thank you

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 Devon Hall · Sep 01, 2012 at 07:27 AM

When writing a script in Unity3D You don't have to use `System.Boolean` you can just set it as true or false since JavaScript already defines the variable in runtime for you.

Also. When you are accessing an object you can't just say as you are defining:

 light.intensity

You have to have some form of access to the actual object. If you are having the script attached to the light itself. Use the Transform class in which is the object the script is attached to itself and it would look a bit like this:

 transform.light.intensity = 0.1;


Since the actual object isn't a light, it has the script Light attached to it.

Also: You don't need the function:

 function CheckLight();

You can rea a global variable like that without having to update it. It will self update.

Also when adding a recharge you have to have some sort of increment in time so I would recommend looking into the Timing class.

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

9 People are following this question.

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

Related Questions

How to change the intensity to go down over time and to go up after colliding with an object. 1 Answer

How to change a light's intensity between two values by pressing a key? 1 Answer

Rotate a camera when my flashlight is on the edge of the screen... Video included 2 Answers

Shader errors 0 Answers

How to prevent Overlapping Lights from combining / adding intensity? 3 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