Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 georgino123 · Oct 31, 2020 at 04:19 PM · ontriggerenterontriggerexitontriggerstayontriggerenter2d

Trigger area around player.

Hello :)

I'm working on my first project (Top-Down 2D game) and I have a question since I looked everywhere and couldn't found an exact similar topic. I will simplify the question with an example as there is no reason for unnecessary details.

There are (let's say 3) stationary Game Objects with specific names (Obj1, Obj2, Obj3) that I want specific events (event1, event2, event3) to happen when my player is NEAR them. (Not necessary collided with them)

I tried 2 ways but none of them triggered the events:

1st way) I added a 2nd Box Collider 2D (isTrigger) to my player and size bigger than my actual player.

2nd way) Added 'isTrigger' box colliders to the 3 objects. (bigger than their actual size)

Added the script to my player on both ways:

void OnTriggerEnter2D(Collision2D Collision)

 {

     if (Collision.collider.name == "Obj1")
     {
         (do event1);
     }
  }

(etc. other 2 objects)

Then I tried again the aboved 2 ways by adding child to my player with attached boxcollider2D (also for the objects) but no combination is working.

I tried to add RigiBody to the objects but nothing changed.

I know I could try the 'reversed' method by making 3 scripts, one on each of my objects but I want to keep it in one script because there are more than 3 objects that I want this to happen.

The whole idea is working perfectly with the 'OnCollision' function but as I mentioned I would like the events to happen even either If my player is inside a specific 'triggered' area, or if I move close to an object so this object will come inside my player's 'triggered area'.

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 Raistlin2015 · Oct 31, 2020 at 05:22 PM 0
Share

This is how I learned. This is done in 3D but the principal is the same.

https://www.youtube.com/watch?v=rQG9aUWarwE&list=PLFt_AvWsXl0dohbtVgHDNmgZV_UY7xZv7

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by PLSMajesticUnity · Nov 02, 2020 at 10:03 AM

You can also use physics 2D overlap circle to learn more about it check out unity docs physics 2D overlap circle. ,If your making a 2d game then you can use a physics 2d overlap circle which just gets info on anything that enters a circle and gets 3 main arguments.

1.the circle radius. 2.the point or the center point of the circle. 3.layer mask so the that it will only trigger on a specific layer.

you write the script in an update method you can use the players position.

 physics2d. overlap circle(player.position,radius,layermask)

This code is only to show you how to place the arguments do not use it for your script there alot of mistakes .

You can learn for unity docs over lap circle.

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

140 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

Related Questions

Can I access a script OnTrigger WITHOUT using getcomponent? 1 Answer

How to use OnTriggerEnter with multiple triggered objects? 1 Answer

How to make multiple gameobjects instantiate from one collider? 3 Answers

issues with on trigger enter and exit 1 Answer

Check that an object is within the bounds of a trigger, but not touching them? 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