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 Tamachan87 · Feb 07, 2015 at 01:48 PM · audiotrigger

Can I have a moving shape as a trigger zone?

I have the following problem:

I want to have a first person player be able to interact with objects around the level. Nothing too complicated; when the player gets within range, and is looking at the object, they can press E and it will play a sound.

Someone recommended I use trigger zones around objects to detect when the player is within range. To me it would make more sense to add a cylindrical shape just in front of the player and have that be the trigger zone, rather than lots of different trigger zones.

Is it possible to do this? Can I attach a trigger to the player and have all game objects I want to interact with in an array?

I'm working in C# so if anyone has any code to help demonstrate their answer that would be great.

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 Mmmpies · Feb 07, 2015 at 02:30 PM

yes, this is for 3D setup as you didn't specify 2D or 3D.

Create an empty GameObject to your player and Add Component to that for a capsule collider.

Tick is trigger and resize so it's bigger than the player. You can move offsets to say where it appears. Move it so it's not triggered by the player, like this:

ChildTrigger

You should be fine with that. I tested it with a cube with a rigidbody that drops onto it.

 using UnityEngine;
 using System.Collections;
 
 public class hitSomething : MonoBehaviour {
 
     void OnTriggerEnter(Collider other)
     {
         Debug.Log (other.name);
     }
 }

And the debug prints out cube.


childtrigger.png (13.0 kB)
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 Tamachan87 · Feb 08, 2015 at 11:41 AM 0
Share

Thanks for the answer. Out of curiosity, you mentioned that it works when you drop a cube onto the trigger zone, but does it work if you move the trigger zone into another object?

avatar image Mmmpies · Feb 08, 2015 at 12:41 PM 0
Share

Yep, just added force to it and put the cube on the ground and it appears to. Looks pretty funny as it hits the cube and falls over like it had few too many drinks, then it reports the terrain triggers as well!

I'm sure you've got a more professional setup :¬) but are you having issues with it triggering?

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Wanting audio to pause when entering a trigger zone 1 Answer

OnTriggerExit stop audio 1 Answer

how do i play a sound if i press a particular key? 2 Answers

Play AudioClip on trigger with First Person Controller 1 Answer

Audio Trigger 3 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