// Use this for initialization void Start() { tutCanvas = transform.GetChild(0).gameObject; nextBtn = GameObject.Find("TutorialNextBtn"); uiElements = GameObject.FindGameObjectsWithTag("TutorialUI"); // save the tutorial UI elements original positions for (int i = 0; i < uiElements.Length; i++) { uiElementsOrigPos[i] = uiElements[i].GetComponent <RectTransform>().position; } currPos = uiElementsPos.ORIG; mascot = GameObject.Find("Mascot").GetComponent <Mascot>(); currentState = TutorialState.STATE_INACTIVE; HideTutCanvas(); walkHere.SetActive(false); minigame = GameObject.Find("Minigame1").GetComponent <Minigame1>(); }
// Update is called once per frame void Update() { if (tutorialOn) { // spent too long in one state, play the mascot's sleep animation timeSpentInThisState += Time.deltaTime; if (timeSpentInThisState >= GO_TO_SLEEP_TIME) { mascot.ChangeState(Mascot.MascotState.STATE_SLEEP); } // initialize new state if changed if (stateChanged) { OnStateChange(); } // play mascot's talking animation if message is currently being typed if (mascot != null) { mascot.isTalking = typing; } // move tutorial UI-elements out of the way in minigame if (minigame.active && minigame.dosingActive) { if (currPos != uiElementsPos.DOSING) { MoveuiElements(0, Screen.height / 2 - 60f); currPos = uiElementsPos.DOSING; } } else if (minigame.active) { if (currPos != uiElementsPos.MINIGAME) { MoveuiElements(-Screen.width / 2, -50f); currPos = uiElementsPos.MINIGAME; } } else { if (currPos != uiElementsPos.ORIG) { MoveuiElements(0, 0); currPos = uiElementsPos.ORIG; } } // update stuff specific to the current state switch (currentState) { case TutorialState.STATE_START: if (nextClicked) { ChangeState(TutorialState.STATE_WALK_PRACTICE_1); } break; case TutorialState.STATE_TARGET_PRACTICE_2: if (nextClicked) { mCamera.lockToPlayer(); ChangeState(TutorialState.STATE_TARGET_PRACTICE_3); } break; case TutorialState.STATE_TARGET_PRACTICE_3: if (nextClicked) { ChangeState(TutorialState.STATE_TARGET_PRACTICE_4); } break; case TutorialState.STATE_TARGET_PRACTICE_4: // check if player has targeted the patient GameObject tp = GameObject.FindGameObjectWithTag("TargetPanel"); if (tp != null && tutorialNPC.GetComponent <NPC>().diagnosed) { ChangeState(TutorialState.STATE_TARGET_PRACTICE_5); } break; case TutorialState.STATE_MINIGAME_PRACTICE_1: if (nextClicked) { ChangeState(TutorialState.STATE_MINIGAME_PRACTICE_2); } break; case TutorialState.STATE_MINIGAME_PRACTICE_2: // check if player has opened the medicine cabinet if (minigame.active) { ChangeState(TutorialState.STATE_MINIGAME_PRACTICE_2_1); } break; case TutorialState.STATE_MINIGAME_PRACTICE_2_1: if (nextClicked) { ChangeState(TutorialState.STATE_MINIGAME_PRACTICE_3); } break; case TutorialState.STATE_MINIGAME_PRACTICE_3: // check if Ibuprofen has been selected if (medCont.medName == "Ibuprofen") { ChangeState(TutorialState.STATE_MINIGAME_PRACTICE_4); } break; case TutorialState.STATE_MINIGAME_PRACTICE_4: // check if pill inside any med cup if (morningCup.medsInThisCup.Count > 0 || afternoonCup.medsInThisCup.Count > 0 || eveningCup.medsInThisCup.Count > 0 || nightCup.medsInThisCup.Count > 0) { ChangeState(TutorialState.STATE_MINIGAME_PRACTICE_SPLITTING_1); } break; case TutorialState.STATE_MINIGAME_PRACTICE_SPLITTING_3: if (nextClicked) { ChangeState(TutorialState.STATE_MINIGAME_PRACTICE_5); } break; case TutorialState.STATE_MINIGAME_PRACTICE_5: // exited minigame if (!minigame.active) { ChangeState(TutorialState.STATE_MINIGAME_PRACTICE_6); } break; case TutorialState.STATE_MINIGAME_PRACTICE_6: // check if medicine given to the patient if (tutorialNPC.GetComponent <NPC>().morningMed[0].isActive) { ChangeState(TutorialState.STATE_ENDING_GOOD_1); } // wrong medicine/dosage given else if (tutorialNPC.GetComponent <NPC>().myHp < 50) { ChangeState(TutorialState.STATE_ENDING_BAD_1); } break; case TutorialState.STATE_ENDING_GOOD_1: if (nextClicked) { ChangeState(TutorialState.STATE_COMPUTER_PRACTICE); } break; case TutorialState.STATE_ENDING_BAD_1: // check if medicine given to the patient if (tutorialNPC.GetComponent <NPC>().morningMed[0].isActive) { ChangeState(TutorialState.STATE_ENDING_GOOD_1); } break; case TutorialState.STATE_COMPUTER_PRACTICE: // check if computer turned on if (computer.GetComponent <Computer>().computerOn) { ChangeState(TutorialState.STATE_COMPUTER_PRACTICE_1); } break; case TutorialState.STATE_COMPUTER_PRACTICE_1: // check if schedule opened if (computer.GetComponent <Computer>().scheduleOn) { ChangeState(TutorialState.STATE_COMPUTER_PRACTICE_2); } break; case TutorialState.STATE_COMPUTER_PRACTICE_2: // check if computer turned off if (!computer.GetComponent <Computer>().computerOn) { ChangeState(TutorialState.STATE_TRASH_PRACTICE); } break; case TutorialState.STATE_TRASH_PRACTICE: if (nextClicked) { mCamera.lockToPlayer(); ChangeState(TutorialState.STATE_COFFEE_PRACTICE); } break; case TutorialState.STATE_COFFEE_PRACTICE: if (nextClicked) { mCamera.lockToPlayer(); ChangeState(TutorialState.STATE_ENDING_GOOD_2); } break; case TutorialState.STATE_ENDING_GOOD_2: if (nextClicked) { ChangeState(TutorialState.STATE_ENDING_GOOD_3); } break; case TutorialState.STATE_ENDING_GOOD_3: if (nextClicked) { ChangeState(TutorialState.STATE_ENDING_GOOD_4); } break; case TutorialState.STATE_ENDING_GOOD_4: if (nextClicked) { ChangeState(TutorialState.STATE_ENDING_GOOD_FINAL); } break; case TutorialState.STATE_INACTIVE: // do nothing... break; } } // tutorial not on, show notifications else { if (stateChanged) { OnStateChange(); } if (mascot != null) { mascot.isTalking = typing; } } }