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

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.