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
2
Question by ConfusedExpert · Feb 24, 2015 at 11:02 AM · inputperformanceeventevent-handling

OnPointerDown vs OnMouseDown

Hello,

I'm trying to understand how the new EventSystem works and how I can use it to make my projects better. Is there any difference between using the OnPointerDown method (implementing the appropriate interface) and using the OnMouseDown? Maybe some performance stuff?

Also, If I have a 20 copies of an object, which share the same script with the same OnPointerDown/OnMouseOver method, is there a way to keep their functionality but not having to attach every single one of them said script? Should I be trying to do something like this? I'm interested in performance issues that may arise.

Thank you,
Asolmanx

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
1

Answer by sniper43 · Feb 25, 2015 at 10:19 AM

If you read the API, you would see that OnPointerDown inherits from the UI.Selectable class and OnMouseDown inheris from MonoBehavior.

So the answer to that is that you use OnPointerDown on UI objects, while using OnMouseDown for in scene objects.

For your second question: You can create an empty parent object, then child as many objects as you like. Assuming those objects have the same component, you can then modify those components.

The easiest way to get children in said parent that have for example have a struct or class Variables attached would be (C# example)

 class SomethingOnParent
 {
 
  void Update()
  {
    foreach(Variable var in gameObject.GetComponentsInChildren<Variable>())
    {
      var.Handle();
    }
  }
 
 }

where the variable has this in it's script

 class Variable
 {
  public void Handle()
  {
    transform.position += transform.forward;
  }
 }


The above wirtten script will move every child object forward for 1 unit every frame.

You can use

 foreach(Transform allTransforms in transform)

to get all chilren transforms (but this returns the parent's transform as well, so handle that appropriately).

If you have any questions about coding, feel free to ask.

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 ConfusedExpert · Feb 25, 2015 at 04:33 PM 1
Share

What I meant was that, by implementing the IPointerDownHandler interface, and using a Physics raycaster and the event system, you can write a "OnPointerDown(PointerEventData data)" method that seems to work just like the On$$anonymous$$ouseDown. I was wondering if there are any differences between those two.

avatar image sniper43 · Feb 26, 2015 at 09:02 AM 1
Share

I've already told you. They belong ot different libraries. That means they have different handling. If you don't need the overhead of UI.Selectable, don't use OnPointerDown. UI.Selectable inherits from $$anonymous$$onoBehaviour at some point, so anyhting On$$anonymous$$ouseDown can do, so can OnPointerDown. But OnPointerDown "assumes" that the object it's attached to is a UI.Selectable object, so you can use appropriate methods for that.

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

20 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

Related Questions

EventType.MouseDrag not working in WebPlayer 0 Answers

checking for keyboard input with exceptions 0 Answers

Help In Making a SphereCast for 3D Tire! Working RayCast Script included! 0 Answers

Can an Input event be 'faked' with a script? 1 Answer

detecting touch on gameObject 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