void SetExit() { if (RoomSpawner.GetRoomAt(transform.position) != RoomSpawner.exitRoom) { this.gameObject.SetActive(false); } }
void StateMachine() { if (state != lastState) { Debug.Log(state); lastState = state; } switch (state) { case States.Idle: if (Vector2.Distance(rb.position, target.position) < followDistance && Vector2.Distance(rb.position, target.position) > attackRadius) { state = States.Following; Debug.Log("following"); } break; case States.Following: //UpdatePath(); if (RoomSpawner.GetRoomAt(target.position) != RoomSpawner.GetRoomAt(this.transform.position)) { state = States.Home; //path.vectorPath.Clear(); // temp, will have "return" movement rb.velocity = new Vector2(); Debug.Log("not following"); } if (Vector2.Distance(rb.position, target.position) < attackRadius) { state = States.StartAttacking; } break; case States.StartAttacking: var attackDir = GetDirection(target.position - transform.position); rb.velocity = new Vector2(); switch (attackDir) { case Direction.North: North.gameObject.SetActive(true); break; case Direction.South: South.gameObject.SetActive(true); break; case Direction.East: East.gameObject.SetActive(true); break; case Direction.West: West.gameObject.SetActive(true); break; } attackCounter = attackTime; state = States.Attacking; break; case States.Attacking: attackCounter -= Time.deltaTime; if (attackCounter <= 0) { DisableHitbox(); } // do animation break; case States.Home: HomePath(); break; } }