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 Dennis_Z · May 31, 2014 at 01:40 PM · audiodistanceclick objectsproximity

How do I let the player interact with objects close to them?

Hello everyone! I'll try to keep it brief and get to the point. I have a little scene for school that I'm trying to put a little extra effort into. Alongside a few OnTriggerEnter effects I have to include, I wanted a few objects that are interactive when the player clicks on them.

Specifically I have a lightswitch and a box. I'm trying to let the box play an audio file when the player clicks on it, and that I pulled off succesfully. However that's not good enough! You can be anywhere in the scene and trigger the sound as long as you can see the box, and that's a bad thing to me.

I'm trying to get it so that the player, when close by (less than 2 meters probably) sees a prompt on OnMouseOver, and then when the player clicks on the box, the audio file plays. The only documentation I could find on this kind of input (only when the player is close to the GameObject) was in Js (that didn't even work) while I work in C#.

If you could help me figure out how to fix the box, that should give me enough information to fix the lightswitch on my own, though I had one question about that as well: can I, when the player clicks on the lightswitch, change it to a 'lightswitch_off' object that would still be able to be reverted back when the player clicks again, or should I make it play an animation?

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
0

Answer by Lovrenc · May 31, 2014 at 01:46 PM

You could use raycast.

You can set the distance of the raycast, so if it hits object, you know it is close enough. Now if that object is one you can interact with, you can popup a note to notify the user he can interact with it, and when he clicks do your action.

About the light switch on / off operation. Its is best if your light switch handles this. When user clicks, simply tell your switch, user clicked on you. And it should know "ok, i am on, i should turn off now".

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

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

Related Questions

Sound volume doesn't change no matter what distance? 0 Answers

How do I only start the audio when player is at max distance 1 Answer

Cheapest way to get distance detection and triggered events. 2 Answers

sound distance between camera and audio source 2 Answers

When I grab an object, it is too close 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