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 crusherxman · Apr 06, 2013 at 01:58 PM · collidertriggertogglepoint light

Toggling point light on/off when clicking a key in a triggered Box Collider area

Hi everyone, I'm currently working on a horror game and I've being spending hours by making scenes and models. I've learned about Mesh Colliders a few months ago and how the "Is Trigger" function works. I've placed a bunch of ceiling lamps to make my scene look brighter and what I need, as the title says; A script for being able to toggle lights when closing up an object (For example, clicking the E button to open/close lights when near the light switch)

I've setup my Capsule Collider with his appropriate scale and range plus with the "Is Trigger" function checked, and yes, my point light is attached with my ceiling lamp.

If you guys have great ideas for making a kind of script like this, please post them as an answer below! I would really appreciate your supports :)

As always, thanks!

-crusherxman

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
2
Best Answer

Answer by Daphoeno · Apr 06, 2013 at 03:14 PM

this can be simply done in javascript with a .active statement. for example :

 var Lights : GameObject;
 var InArea : boolean = false;
 var LightsOnAndInArea : boolean = false;
 var LightsOffAndInArea : boolean = false;
 
 function Start ()
 {
     Lights.active = true;
 }
 
 function Update ()
 {
     if(Input.GetKeyDown(KeyCode.E) && LightsOnAndInArea == true){
         Lights.active = false;
     }
     if(Input.GetKeyDown(KeyCode.E) && LightsOnAndInArea == false){
         Lights.active = true;
     }
         
     if(Lights.active == true && InArea == true){
         LightsOnAndInArea = true;
     }
     if(Lights.active == false && InArea == true){
         LightsOnAndInArea = false;
     }
     
     if(Lights.active == true && InArea == false){
         LightsOnAndInArea = false;
     }
     if(Lights.active == false && InArea == false){
         LightsOnAndInArea = false;
     }
 }
     
 function OnTriggerEnter (other : Collider) 
 {
     InArea= true;
 }
     
 function OnTriggerExit (other : Collider) 
 {
     InArea= false;
 }

There you go now you can toggle on and off

Daphoeno

Comment
Add comment · Show 16 · 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 crusherxman · Apr 06, 2013 at 03:48 PM 0
Share

It worked well, but when I disable my light it wont open, little help?

avatar image crusherxman · Apr 06, 2013 at 04:33 PM 0
Share

Yeah, like turning the light on and off.

avatar image Daphoeno · Apr 06, 2013 at 06:57 PM 0
Share

I'll have another look at the script

avatar image Daphoeno · Apr 06, 2013 at 07:42 PM 0
Share

Finished refining the script. Try it now.

avatar image crusherxman · Apr 06, 2013 at 11:12 PM 0
Share

Great! But now how do I disable my light when entering my scene? It keeps getting on when it's disabled in my editor.

Show more comments

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

12 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

Related Questions

Can't click gameobject when over another trigger? 1 Answer

Using a trigger collider to detect enemies. 1 Answer

Have something be a trigger and a collider? 1 Answer

Other function that is similar to OnTriggerStay 3 Answers

Animation not playing but trigger works 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