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 /
This question was closed Nov 29, 2017 at 10:06 PM by Igor_Vasiak for the following reason:

Did it another way around.

avatar image
0
Question by Igor_Vasiak · Nov 29, 2017 at 09:15 PM · scripting problemphysics2dboolcheckinherited-members

External Physics2D.OverlapCircle check not working.

I wrote this piece of code inside an abstract class:

 public bool IsPlayerInRange (Transform transform, float range)
 {
     return Physics2D.OverlapCircle(transform.position, range, LayerMask.NameToLayer("Player"), Mathf.Infinity, Mathf.Infinity);
 }

And then I wrote this inside another class that inherited from the abstract class:

 if (IsPlayerInRange(transform, 4))
     Rbody2D.DashSides(stats.movement_speed * 2, 0.2f, false);

But somehow it doesn't check for the player. Why? Thanks in advance.

Comment
Add comment · Show 3
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 MacDx · Nov 29, 2017 at 09:26 PM 0
Share

Does you abstract class inherits from monobehaviour?

avatar image Igor_Vasiak MacDx · Nov 29, 2017 at 09:29 PM 0
Share

Yep. It does.

avatar image MacDx Igor_Vasiak · Nov 29, 2017 at 09:31 PM 0
Share

Consider name collision then. Your transform parameter might be interfering with the one from the monobehaviour class

1 Reply

  • Sort: 
avatar image
2

Answer by Buckslice · Nov 29, 2017 at 09:25 PM

the minDepth argument for Physics2D.OverlapCircle should be negative infinity probably

Comment
Add comment · Show 4 · 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 Igor_Vasiak · Nov 29, 2017 at 09:29 PM 0
Share

I've always done it this way and... Well, it always worked for me. But I've always used Physics2D.OverlapCircle directly to its purposes. Never like this, as a boolean method inside an abstract class...

Outside of the abstract class it works well, but when I bring the checker to the inside of it, well, then it doesn't work.

avatar image Igor_Vasiak · Nov 29, 2017 at 09:34 PM 0
Share

This just made my game get down to 5 fps.

avatar image Buckslice Igor_Vasiak · Nov 29, 2017 at 09:40 PM 0
Share

Hmm thats weird, are you getting null reference exceptions or something? $$anonymous$$aybe post some more code

avatar image Igor_Vasiak Buckslice · Nov 29, 2017 at 10:05 PM 0
Share

No... Not any null references. But now I've decided to give up and use a faster solution: not using Physics2D.OverlapCircle inside both FixedUpdate and LateUpdate at the same time. I'm using an EmptyObject with a Trigger CircleCollider right now, that returns what I want... :)

I'm such a bug creator - can't solve bugs guy... Anyway, thanks for trying. I'm closing this question now.

Follow this Question

Answers Answers and Comments

129 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

Related Questions

Where should I call Physics2D.Raycast ? 0 Answers

checking Bool true from another Script? 2 Answers

groundCheck in small beginner project not working properly 0 Answers

How to change a Bool for only a single prefab GameObject? 1 Answer

How can I slow the velocity of my player without it affecting fall speed? 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