Switch Command

In this task you will have to add another command which binds the tab key to switch between characters.

Requirements for the task:

  • A switch must change the target of camera to the new character, by calling SetTarget on the CameraMovement script.
  • All input must be directed to the new character by changing the currentActor variable in InputHandler
  • The switch must still get next character if there are more than two characters in the scene. You can test that this works by selecting one of the character gameobjects in hierarchy and pressing Ctrl + d for duplicate.
  • The switch must not cause errors when there is only a single character in the scene.

Options for accessing CameraMovement:

  • Since there is only a single CameraMovement in the scene, it can be found by GameObject.FindObjectOfType(). This would not always work with multiple camera movement scripts though.
  • Main camera of the scene can be accessed through Camera.main. So a component in a parent gameobject from that camera can be retrieved by Camera.main.GetComponentInParent().
  • Create a serialized variable in InputHandler and assign it from the editor. See currentActor in InputHandler.

Hints:

  • Our design decisions in the first task force us to send an object reference to the command on Execute(). Although we can simply ignore that argument for some commands which don’t need to work with the active object and send the actual receiver through the constructor.
;