Best Practices for touch event on GameObject C#,Best Practices for touch events C#

Hi guys,

It’s better to detect a touch event on a GameObject in a generic Main Script that handles multiple types of object (player, enemy, item etc) or detect the event in the script attached to the GameObject itself (enemy.cs, item.cs, player.cs)?

Main.cs
or
Enemy.cs, Player.cs, Item.cs

Thank you in advance!

I’d say it’s better to handle touch in one script only to avoid any conflict in design.

Then this script can forward events to whatever is touched, using interfaces for example, such as

public interface IHandleTouchTap
{
    void OnTap ();
}
public interface IHandleTouchDoubleTap
{
    void OnDoubleTap ();
}
public interface IHandleTouchDrag
{
    void OnDrag (Vector2 drag);
}
public interface IHandleTouchMultiple
{
    void OnMultiTouch (int touchCount);
}
// etc..