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 SpeedTutor · Apr 17, 2013 at 08:03 PM · timerflashlightintensity

Flashlight timer

Hello,

I'm trying to create a script which has a simple timer in the background, and change the intensity of a light source (Spotlight attached to a torch mesh).

Not really sure how to reference the light source and change it's intensity. I've been looking at this for too long...

 private var startTime;
 private var restSeconds : int;
 
 var Flashlight : Light;
 var countDownSeconds : int;
 
 function Awake() 
 {
  startTime = Time.time;
     
  var guiTime = Time.time - startTime;
  restSeconds = countDownSeconds - (guiTime);
 }
 
 function update() 
 {
     if (restSeconds == 60)
     {
     Flashlight.Light.intensity = 1;
     Debug.logWarning("Light goes down");
     }
 }
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 iwaldrop · Apr 17, 2013 at 09:19 PM

Do you ever assign a value to Light? What's wrong with just using Flashlight.light?

Make sure that Flashlight inherits from Monobehaviour, that the GameObject that Flashlight is on has a Light Component attached to it, and call the following:

 Flashlight.light.intensity = 1;
Comment
Add comment · Show 6 · 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 SpeedTutor · Apr 17, 2013 at 10:56 PM 0
Share

I have the script attached to the spotlight, and placed the 'Light component' into the free variable slot. Yet it still does nothing.

How would I set the intial value for the light intensity?

 function Awake() 
 {
  Flashlight.Light.intensity = 3;
 }


Yet when I do this, I get a nullreference error. Not really sure how to proceed.

Thanks for the help.

avatar image iwaldrop · Apr 17, 2013 at 11:01 PM 0
Share

It looks like you're intending to use Flashlight.intensity. But, again, you don't need a variable to store a reference to a Light, because every Component already contains a reference to the Light attached to the same GameObject. I misunderstood your code earlier, so light.intensity should get the job done too. :)

avatar image Dracorat · Apr 17, 2013 at 11:07 PM 0
Share

Remember that caps are important - it's just plain light.intensity and also the intensity value is in the range of 0 to 1 where 0 is "off" and 1 is "full on".

For some special lights, and only if you're using HDR, a value greater than 1 might be useful, but I doubt for this.

avatar image Triqy · Apr 17, 2013 at 11:10 PM 0
Share

Are you trying to make a timer and as the timer goes down the intensity goes down with it?

avatar image SpeedTutor · Apr 17, 2013 at 11:14 PM 0
Share

So, I added

 Flashlight.light.intensity = 2;

On awake and that definately changes the intensity. I think I've broken the timer as I don't think it ever reaches 60 seconds.

As for the timer, yes. At a specific time, I want the intensity to decrease slightly.

Show more comments
avatar image
0

Answer by Dracorat · Apr 17, 2013 at 11:17 PM

These two lines need to be in the beginning of the Update function, not the Awake function:

 var guiTime = Time.time - startTime;
 restSeconds = countDownSeconds - (guiTime);
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

14 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

Related Questions

Flashlight Intensity with ScrollWheel 1 Answer

How to create. The most basic flashlight possible. 1 Answer

Unity and Playmaker - Flashlight Decrease Logic 0 Answers

How do you write a Pauseable-Timer Script in Unity JavaScript? 1 Answer

Adding time before a script is initiated. 2 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