Ejemplo n.º 1
0
  public void GenerateNewCustomer() {
    if (customerPrefabs.Count > 0 && customersServed < customersToServe) {
      pitchCanvas.gameObject.transform.parent.gameObject.SetActive(true);
      GameObject customerObject = GameObject.Instantiate(customerPrefabs[0]);
      currentCustomer = customerObject.GetComponent<Customer>();


      if (speechTextBox == null) {
        speechTextBox = GameObject.FindGameObjectWithTag("SpeechBubble").GetComponent<Text>();
      }
	  if (currentCustomerImg == null) {
		currentCustomerImg = GameObject.Find("CustomerSprite").GetComponent<SpriteRenderer>();	
	  }
	  currentCustomerImg.sprite = currentCustomer.customerImg;
      currentCustomer.speechTextBox = speechTextBox;
      customerPrefabs.RemoveAt(0);

      for (int i = 0; i < newProblems.Count; i++) {
        Problem problem = newProblems[i];
        if (problem.problemType == currentCustomer.problemType) {
          currentCustomer.problem = problem;
          newProblems.RemoveAt(i);
          currentCustomer.PitchProblem();
          if (pitchCanvas) {
            pitchCanvas.enabled = true;
			currentCustomerImg.enabled = true;
          }
          if (SoundManager.instance) {
            SoundManager.instance.PlayNewCustomerArrival();
          }
          if (cureMgr) {
            cureMgr.StartTheCure();
          }
          return;
        }
      }
      throw new UnityException("Unable to find problem for customer with problemType: " + currentCustomer.problemType);
    } else {
      int avg = 0;
      for (int i = 0; i < completedCustomers.Count; i++) {
        avg += completedCustomers[i].problem.rating;
      }
      avg /= completedCustomers.Count;
      gameOverCanvas.gameObject.SetActive(true);
      GameOver gameOver = gameOverCanvas.GetComponent<GameOver>();
      gameOver.averageRating = avg;
      Debug.Log("Avg: " + avg);
      gameOver.ShowRating();
    }
  }