Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 sportente · Mar 17, 2016 at 10:24 PM · c#colliderlight

How to switch light off after game object has leaved another game object?

I have overall 3 game objects in my game. Two bars and one sphere. Bar 1 is at x=-6 and y=-2 and bar2 at x=6 and y=2; I would like to follow bar 1 and as soon as my sphere leaves bar 1 I would like to switch off the light for some seconds. So that the player has to move the sphere on bar 2 without seeing anything (based on experience on what he saw).

Is this possible? I thing with a collider function?

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 MechanicalGaming · Mar 17, 2016 at 10:30 PM 0
Share

Yeah with a collider would be best. $$anonymous$$y way of doing it probably isn't the best and maybe a lot of programmers out there might say that it is a bad way to do it but, on leave destroy the light and when (if) the player gets to the other bar instantiate a prefab of the light. Also, you could put it on a timer so that if the player doesn't get to the bar in time then they fail other wise they can just try for ever.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by jebemti · Mar 17, 2016 at 10:49 PM

You can add any collider on an object and set "Is Trigger" to true. Then these functions will be called on any script attached to the same GameObject:

OnTriggerEnter

OnTriggerExit

OnTriggerStay

In these functions you can enable/disable the lights in your scene.

Example:

 void OnTriggerEnter(Collider other) {
     light.enabled = true;
 }
 
 void OnTriggerExit(Collider other) {
     light.enabled = false;
 }
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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

,How to add value to a Light range that is counting down. 0 Answers

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Smooth Movement on Geometry Collission? 0 Answers

How to set a Collider of a GameObject to Inactive similar to the SetActiveMethod 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