Pointer Events VS. Mouse Events?

Ok. So I went through the course, then wanted to do a simple (or so I thought) drag-and-drop operation.

This simple operation ended up being a rabbit hole of Pointer Events Vs. Mouse Events.

It looks like, since I’m planning targeting mobile as well as PC, I should work with Pointer events. But this was not at all covered in the course. So I’m wondering if anyone has some advice. I was not planning on making user-movable game objects part of the UI, but it seems like I might need to in using Pointer Events instead of Mouse Events.

Hi Dylan,

In which course are you?

For UI elements, it probably makes more sense to use pointer events as they are inherited from UI related classes, while OnMouseDown is part of MonoBehaviour.

I finished the 2-d one. I’ll probably go through the multiplayer course once I’m done with my core game. If there’s a good lecture on this in the 3-d course, I have access to that as well.

But regarding the original question:
If I’m planning on making the various versions of the game very cross-platform ready, does it make more sense to use OnMouseDown / OnMouseDrag for objects that are not specifically in the UI, (something like the placed towers in the Glitch Garden example) to spawn objects within the UI and use pointer events? It seems I need to attach Standalone Input Modules to these objects to interpret Pointer events. Should I have, say, 30-40 objects with this component attached at a time, will that cause issues?

That’s a good question, and I think it depends (as always ;)). I almost never use OnMouse* methods because I often need more information. Check the parameter of the method in the example to learn what data you could get during runtime. Maybe it is also relevant for your game.

Take a look at the available interfaces. Actually, they should cover everything you need for your game.

Generally, it is recommended to test a technique instead of relying on the opinion of some random person on the internet. Only then you will be able to tell whether you found a good solution for your project.

Should I have, say, 30-40 objects with this component attached at a time, will that cause issues?

Probably not but test it anyway. If you get performance issues, you’ll probably have to do some performance optimisation. You can find information on this subject on the official Unity website and in the official Unity videos on Youtube.

Depending on your game, it could even be sufficient to cover everything with one mouse click and to look the relevant data up in a dictionary or something like that instead of handling dozens of single objects in the scene.

Thank you.
As an aside, one thing GameDev might consider is a course aimed at experienced programmers / developers getting additional training. What seems to be missing from the market right now is content that targets people who know how to build software, but don’t specifically know the environment they’re aiming at learning.

Our RPG course caters to intermediate programmers. If you have additional ideas, you could share them here:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.