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
1
Question by JenoahKers · May 08, 2018 at 07:51 PM · collisioncollidertrigger

How can I let a trigger detect if a collider is inside (at start)

Hi everybody

I am currently building a game about being on another planet and such... Whenever the player is in a safezone, the player will be able to recharge the oxygen they are carrying around. I've got the safezone setup, but I only want it to be able to work whenever a oxygengenerator is inside of it.


Since the building in which the oxygen generator is able to stand in, is a prefab (just as the oxygen generator), I want to be able to my every safezone/building to check for themself if an oxygen generator is placed in the safezone/building.

How can I achieve this?
Thanks upfront!


EDIT
I might forgot to mention that the player is a seperate game object. The player is able to walk in and out of the safezone, though the generator cannot move when playing the game. (It can be build however).

I've tried using OnTriggerStay with a tag, but this is not working. By default, some zones already have some generators in them.

Comment
Add comment · Show 2
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 fluxhackspro · May 09, 2018 at 08:31 AM 0
Share

Simply use OnTriggerStay if you want to stay with triggers. Ifor not you can use tags and distance. Which in my opinion is less effective

avatar image JenoahKers · May 09, 2018 at 08:34 AM 0
Share

@fluxhackspro I thought of that but doesn't that require one of the objects to move? Because whenever I load up a safezone with a generator already in it, it won't detect it...

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by tormentoarmagedoom · May 09, 2018 at 08:37 AM

Good day.

You have the OnTriggerStay() funtion, which will be executed when a collider is inside the trigger of the gameobject (every frame).

Thena good solution is to create a tag for OxigenGenerator Object fro example "OxiGen", and check if the collider that is inside have this tag.

 void OnTriggerStay(Collider other)
     {
         if (other.gameObject.tag == "OxiGen")
         {
             Debug.Log ("Oxigen generator detected!!");
         }
     }

Byeee!

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 JenoahKers · May 09, 2018 at 07:39 PM 0
Share

Hi @tormentoarmagedoom, Thanks for your reply.

Sadly it doesn't really work as I was hoping. In fact, it doesn't even register that the generator is inside the safezone. This probably is so because it is already placed in the safezone before spawn.

Any other ideas?

Thanks ;)

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

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

Related Questions

Collisions - bounce of walls but not from characters (while still reacting with them) 0 Answers

Something wrong with destroying script 0 Answers

Extracting child trigger from compound collision 0 Answers

Trigger2D not working 0 Answers

Collider won't collide with a 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