What I want here is to achieve a movement mechanism similar to how the player move the character in the GO games of squareEnix, where you move the character along a predefined path drawn in the scene.
Any help or some tips on achieving this ?
I’d create a custom interface, name it something simple like… “IGameTickReceiver” or something. And have on it a method called ‘Tick’ or something like that:
public interface IGameTickReceiver
{
void Tick();
}
Now any gameobject that updates on the tick has a component on it that implements this interface. The ‘Tick’ method being the method that gets called.
So if you have a enemy that moves every game tick, in this method it does the logic to move. Like the snakes in Lara Croft GO change their position whenever Tick is called on it.
Then you have some ‘GameManager’ class, in it you have a Regist and Unregister method for IGameTickReceiver. In the OnEnableof any script that implements this interface, you register it with the GameManager, on OnDisable, you unregister it.
THEN, finally… every time the player interacts (makes a move choice), you call the ‘Tick’ method on all registered objects.
public class GameManager
{
private HashSet<IGameTickReceiver> _entities = new HashSet<IGameTickReceiver>();
public void Register(IGameTickReceiver entity)
{
_entities.Add(entity);
}
public void Unregister(IGameTickReceiver entity)
{
_entities.Remove(entity);
}
public void Tick()
{
var e = _entities.GetEnumerator();
while(e.MoveNext())
{
e.Current.Tick();
}
}
}
This is a naive implementation, never call register or unregister from a Tick method.
And that’s basically it.
You may want to include a parameter on the Tick method that is the players input choice. This way the ‘player’ object can move the way it is supposed to. And other objects may react to player input in interesting ways.