// Start is called before the first frame update void Start() { anim = GetComponentInChildren <Animator>(); GameEvent.current.onCustomerSpawn += CustomerSpawned; bookshelves = bookshelfController.GetComponent <BookshelvesController>(); pickingBookDuration = Random.Range(2, 10); currentState = customerState.entering; //if (initialCharacter) //{ // currentState = customerState.standing; //} //else { // currentState = customerState.entering; //} temp = bookshelves.GetABookShelf(); }
void Update() { Vector3 curMove = transform.position - previousPosition; curSpeed = curMove.magnitude / Time.deltaTime; previousPosition = transform.position; timer += Time.deltaTime; anim.SetFloat("Speed_f", curSpeed / 4); var isClosed = timeController.IsClosingTime(); switch (currentState) { case (customerState.entering): if (timer >= moveDelay && temp != null) { agent.SetDestination(temp.transform.position); currentState = customerState.browsing; } if (isClosed) { currentState = customerState.leaving; if (temp != null) { temp.GetComponent <BookshelfController>().setOccupid(false); } } break; case (customerState.browsing): dist = agent.remainingDistance; if (dist != Mathf.Infinity && agent.pathStatus == NavMeshPathStatus.PathComplete && agent.remainingDistance == 0) { agent.transform.rotation = (temp.GetComponent <BookshelfController>().transform.rotation); if (timer >= pickingBookDuration) { currentState = customerState.buying; temp.GetComponent <BookshelfController>().setOccupid(false); } } else { timer = 0.0f; } if (isClosed) { currentState = customerState.leaving; if (temp != null) { temp.GetComponent <BookshelfController>().setOccupid(false); } } break; case (customerState.buying): agent.SetDestination(cashierObject.transform.position); currentState = customerState.paying; break; case (customerState.paying): dist = agent.remainingDistance; if (dist != Mathf.Infinity && agent.pathStatus == NavMeshPathStatus.PathComplete && agent.remainingDistance <= 0.2) { if (timer >= buyingBookDuration) { currentState = customerState.leaving; moneyController.AddMoney(30); } } else { timer = 0.0f; } break; case (customerState.leaving): agent.SetDestination(exitTarget.transform.position); currentState = customerState.remove; break; case (customerState.remove): dist = agent.remainingDistance; if (dist != Mathf.Infinity && agent.pathStatus == NavMeshPathStatus.PathComplete && agent.remainingDistance <= 0.2) { Destroy(this.gameObject); customerSpawner.DecrementCustomerCount(); } break; case (customerState.standing): break; } }