Mar 20

Simplified SeekSteer and made my own script for moving objects between waypoints. The MovingPlatform now works much better.

Mar 19


So I wanted to use an interface reference as a public variable, but it wouldn’t show up in the inspector. After many hours researching and trying different things, I finally settled for using abstract classes instead, and using the unity way of adding scripts to objects as my interface.

I made a pad with a button on it. This button is my switch. When something (player or box) moves onto it, it should trigger an event in another target object. So I wanted to have a SwitchTrigger interface for the target of my switch object.

What I did instead was the following:

Then I have to create an explicit class inheriting this abstract class for the specific GameObject I want it on.

I then add the script SwitchTriggerTarget to my MovingPlatform object.

MovingPlatform object also has a MovingPlatform script, which basically just makes sure other objects on MovingPlatform object follows it when it moves. This is done by parenting.

The platform movement is done by another script. Just add the modules you want onto the GameObject, and then make a prefab of it. Modular and nice.

Now, my SwitchPad (the one you walk on to trigger the button), looks like this.

The highlighted row: By using the abstract class as the type, only GameObjects with scripts inheriting from SwitchTarget, like MovablePlatformSwitchTarget, can be dragged onto the target in the inspector.

This works, but everything would have been easier if an interface could be used as type and shown in inspector…