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 Daniel Girgis · Nov 01, 2010 at 01:52 PM · lightingpointlightonoff

flashlight on/off

how do i turn on and off a pointlight i made the torch and everything and i cant figure out how to access this thankyou btw i prefer C# but dont mind if u cant

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
1

Answer by skovacs1 · Nov 01, 2010 at 02:03 PM

Two simple approaches are that you could enable/disable the light or zero/un-zero the intensity:

//Somewhere Light bar = foo.GetComponent<Light>();

//Somewhere later, switch the light on/off if(bar) bar.enabled = !bar.enabled;

or

//Somewhere Light bar = foo.GetComponent<Light>(); float oldIntensity = 0.0f;

//Somewhere later, switch the light on/off float temp = bar.intensity; bar.intensity = oldIntensity; oldIntensity = temp;

Comment
Add comment · Show 5 · 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 Daniel Girgis · Nov 02, 2010 at 05:55 AM 0
Share

i get script errors is this java script or somthing or do i need to add buttons to it sorry i just keep getting script errors saying name 'foo' does not exist in the current context

avatar image skovacs1 · Nov 02, 2010 at 02:13 PM 0
Share

This is valid c#/mono. foo is an example variable for your flashlight GameObject which you would have to create, find and store however you prefer. If this script is in a class+function attached to your light source, then you can just remove foo and call GetComponent directly. Because you didn't provide any code or context for how or where you were using this script, there is no way to know what you have setup in your code or not.

avatar image Daniel Girgis · Nov 04, 2010 at 05:37 AM 0
Share

oh i get ya ill give it a go do i need to add a button input to perform this function?

avatar image skovacs1 · Nov 04, 2010 at 02:01 PM 0
Share

The "Somewhere" part only implies that the variable oldIntensity be declared outside the function and that the variable bar should also be declared outside the function so that you aren't calling GetComponent every frame - in which case the GetComponent call would be in Start(). The rest of this code you could put into a function of your own and call it based on animation event, button press from the input manager, button press from the GUI or even after a certain amount of time or you could do it in Update() under many of the same conditions - That's up to you.

avatar image skovacs1 · Nov 04, 2010 at 02:08 PM 0
Share

I'm not really sure why you would ask if you needed to add a button to perform the function. This is simply code that you can call however you like. It needs to be within a function within a class somewhere, but what you do with it and when is up to you. This leads me to believe that you might have some misunderstandings about Unity scripting. If that is the case, I would suggest you look through the tutorials and documentation for a bit because simply accessing a point light could be the least of your worries if you don't know what you're doing.

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

1 Person is following this question.

avatar image

Related Questions

Low shadow quality from distance light 2 Answers

Custom shader light blending 0 Answers

Terrain Shading 1 Answer

point light gets brighter and darker as it moves 0 Answers

Lighting problem and glitch. 4 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