private void Update() { //If the title screen is active, move using the up/down and WS keys. if (titleScreen.activeInHierarchy) { //Activate the title screen cursor and deactivate the level select cursor -- ran when the title screen loads. if (!titleScreenCursor.IsActive()) { titleScreenCursor.SetActive(); } if (levelSelectionCursor.IsActive()) { levelSelectionCursor.Deactivate(); } //Move to the next or previous cursor. if (Input.GetKeyDown("down") || Input.GetKeyDown("s")) { titleScreenCursor = titleScreenCursor.ActivateNext(); titleScreenIndex = titleScreenCursor.GetIndex(); } else if (Input.GetKeyDown("up") || Input.GetKeyDown("w")) { titleScreenCursor = titleScreenCursor.ActivatePrevious(); titleScreenIndex = titleScreenCursor.GetIndex(); } //Activating menus } else if (levelSelectionScreen.activeInHierarchy) { //Activate the level selection screen cursor and deactivate the level select cursor -- ran when the level selection screen loads. if (!levelSelectionCursor.IsActive()) { levelSelectionCursor.SetActive(); } if (titleScreenCursor.IsActive()) { titleScreenCursor.Deactivate(); } //Move to the next or previous cursor. if (Input.GetKeyDown("right") || Input.GetKeyDown("d")) { levelSelectionCursor = levelSelectionCursor.ActivateNext(); levelSelectionIndex = levelSelectionCursor.GetIndex(); } else if (Input.GetKeyDown("left") || Input.GetKeyDown("a")) { levelSelectionCursor = levelSelectionCursor.ActivatePrevious(); levelSelectionIndex = levelSelectionCursor.GetIndex(); } } HandleSelection(); }
//If there is a previous cursor, deactivate the current one and activate the previous. //Return this cursor if there is no previous. public CursorBehaviour ActivatePrevious() { if (previousCursor) { Deactivate(); previousCursor.SetActive(); return(previousCursor); } return(this); }
//If there is a next cursor, deactivate the current one and activate the next. //Return this cursor if there is no next. public CursorBehaviour ActivateNext() { if (nextCursor) { Deactivate(); nextCursor.SetActive(); return(nextCursor); } return(this); }