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 Jaidan · Jan 29, 2015 at 09:34 PM · lightingnooblights

Turn all game lights off after a collision

I would like to find out how i can have all the lights in my game be turned of so the scene becomes pretty much pitch black. So when one of my characters collides with another object i want to have he lights intensity turn down. I am very very new to unity so it would help if you also stated what i would attach the script to and stuff like that. Thanks

Comment
Add comment · Show 1
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 meat5000 ♦ · Jan 29, 2015 at 08:34 PM 0
Share

Learn

1 Reply

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

Answer by Hexer · Jan 29, 2015 at 09:42 PM

I would use,

FindGameObject("NameOFgameObj_with/Lightsource").GetComponent(Light).enabled=false;

but when you have to many lightsources in your scene this can be a little bit messy. In that case you want to make some kind of FADE IN effect. There are plenty of tutorials on the internet.

...Or add some kind of transparant/black layer.

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 Jaidan · Jan 29, 2015 at 09:47 PM 0
Share

Okay thanks for the reply, I do have 3 lights in the scene but I will try and use what you suggested, and this may sound stupid, but do I put that in the void start and add put it in a if statement? So if there is a collision then the lights fade out and what would I attach this too? Thanks so much for you answer

avatar image Hexer · Jan 29, 2015 at 10:08 PM 0
Share

1 : You add void OnTriggerEnter() and put the disable lightsource code in an if-statement.(if you use the script as seen below, make sure to add the tag (Player) to the player. (or change it to any desired tag)

     void OnTriggerEnter(Collider other)
     if(other.gameObject.tag == "Player"){
 FindGameObject("NameOFgameObj_with/Lightsource").GetComponent(Light).enabled=false;
 }

2 : You attach your script to the object with the collider. (btw if you are using a solid object like a cube, you want to make sure the collider is a little bit bigger than the object)

here is a link to Unity references I use it all the time when trying to make a script.: http://docs.unity3d.com/ScriptReference/Collider.OnTriggerEnter.html

http://docs.unity3d.com/ScriptReference/GameObject-tag.html The first link tells you more about the use of OnTriggerEnter and the second link is a reference to gameObject.tag I also suggest to watch a video about using tags.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Why do 2D Lights render past shadowcasters. 1 Answer

Some lights aren't working. 0 Answers

Trying to make light pass through object 0 Answers

Why my 2D shadows have low resolution? 0 Answers

Multiple lights problem on a single sprite. 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