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 B3NN · May 26, 2010 at 07:06 AM · collisioncollidertriggerlightswitch

Trouble with light switch

I know there are quite a few topics to do with light switches but I'm really having trouble getting this to work.. I have 3 objects; - sphere (player) - cube (wall) - light

I want to make it so when the player hits the wall, it switches on a light.. I'm trying to get all this done in JavaScript but because I'm still learning it seems to be giving me trouble.. any help would be great! ^_^ 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 Extrakun · May 26, 2010 at 07:11 AM 0
Share

Can you describe what you have done and tried? You may want to check up Collier and the trigger functions in the documentation for starters

3 Replies

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

Answer by B3NN · May 27, 2010 at 12:57 AM

Well I finally got this thing working!

var linkedLight : Light; //linked to switched off light

function OnControllerColliderHit(triggerLight : ControllerColliderHit)

{

if(triggerLight.gameObject.tag == "wall") //"wall" is the tag on the wall I'm colliding with

{

linkedLight.enabled = true;

}

}

Sorry to bother everyone with the question.. but thanks a lot for the resources, it took me a while, but I finally figured it out :) Now I can add some variables to toggle the light back off again!

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
avatar image
0

Answer by bowditch · May 26, 2010 at 03:33 PM

Make sure you have physics colliders on all of your GameObjects.

Then, make sure you enable the "Is Trigger" in the Wall GameObject.

You can choose from a number on OnCollision Functions to complete this.

Is this helpful? I can give you more advice if you have more details to share about what you want to accomplish.

You may also want to check out Tornado Twins - Understanding Triggers Video Tutorial

Comment
Add comment · Show 1 · 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 B3NN · May 26, 2010 at 11:44 PM 0
Share

I have physics colliders on the sphere and the wall, I didn't think I would need one on the light because it's floating above the player. When I turned on "Is Trigger" for the Wall GameObject it made me run through it.. so I've made a new one just in front which acts as the trigger but doesn't get rendered, I think that way I can still collide with it even though it can't be seen.. The biggest problem I am having now is actually switching the light, I can't seem to find any way of making it work..

avatar image
0

Answer by B3NN · May 27, 2010 at 12:20 AM

Turns out my light switch was fine.. I tried:

var linkedLight : Light; //this is liked to a light which is switched off

function Update ()

{

if (Input.GetKey("q"))

{

linkedLight.enabled = true;

}

}

This worked fine.. when I run the game and press "q" the light switches on.. so I guess my problem lies in the collision... I'm using:

function OnCollisionEnter(triggerLight : Collision)

{

if(triggerLight.gameObject.tag == "wall")

 {

 linkedLight.enabled = true;

 }

}

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

No one has followed this question yet.

Related Questions

Using shadows as Triggers? 1 Answer

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

Player detecting collision when crouching 1 Answer

Compound collider does not trigger the parent 1 Answer

Missing taps on triggers/collider 0 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