Answers for "What is the Command Pattern?"

1

What is the Command Pattern?

class MoveCommand
{
   Transform moved;
 
   public MoveCommand(Transform target)
   {
       moved = target;
   }
 
   public void Execute()
   {
       moved.Translate(Vector3.back);
   }
}


//then where we detect input
if(Input.GetKeyDown(Keycode.S))
{
   MoveCommand command = new MoveCommand(transform);
   command.Execute();
}
Posted by: Guest on September-02-2021

Code answers related to "What is the Command Pattern?"

Browse Popular Code Answers by Language