I like the pattern of putting MonoBehaviours on clickable things, and each one can be completely different if you use a common interface among them all.
Using Interfaces in Unity3D:
SendMessage is kind of antiquated. The way to do things today is to make an interface.
That way you say “is there this interface?” and check if it’s not null, then call the method you want if it is.
Don’t be afraid, it’s pretty simple, and it’s way more powerful. Here, soooper-quickly:
// stick this in its own file, usually IMyInterface.cs
public interface IMyInterface
{
void MyMethod( int arg1, string arg2);
}
Now, in whatever Monobehaviors you have, you implement that interface, which ba…
Looks reasonable... you might get some benefit by extracting common methods into some kind of interface, which is a pattern that works really well with Unity and MonoBehaviors. MBs can then implement specific interfaces and be found because they implement those interfaces.
For instance, you might have an IAttackable interface that can represent a target that can be attacked. Some of its methods might be "what can hurt you?" and "you have been attacked by ..." This also means when a projectile …
Check Youtube for other tutorials about interfaces and working in Unity3D. It’s a pretty powerful combination.
1 Like