void PickNewState() { if (currentState == State.Idle) { currentState = State.Shoot; animDuration = SHOOT_DURATION; FireBullet(GUN_1); FireBullet(GUN_2); } else if (currentState == State.Shoot) { currentState = State.Idle2; animDuration = IDLE_CYCLE_DURATION * Random.Range(2, 5); } else if (currentState == State.Idle2) { currentState = State.Travel; CellPosition newCell = GetRandomCell(); Vector3 newPos = dweller.GetGridWorld().GetRealPosition(newCell); Vector3 currentPos = gameObject.transform.position; float distance = (newPos - currentPos).magnitude; animDuration = distance * FLIGHT_DURATION + FLIGHT_BASE; dweller.AnimateToCell(newCell, animDuration, 0.0f, 2.0f); } else if (currentState == State.Travel) { currentState = State.Idle; animDuration = IDLE_CYCLE_DURATION * Random.Range(2, 5); eyesFocused = false; } }
void Update() { moveTimer -= Time.deltaTime; if (moveTimer < 0) { ResetMoveTimer(); moveTimer += moveTime; CellPosition next = GridWorld.getInstance() .FindRandomCellWithout(DwellerType.Enemy, GridClass.EnemyGrid); dweller.AnimateToCell(next, moveTime); } }
void Update() { timer += Time.deltaTime; if (mode == Mode.Wait && timer >= WAIT_TIME) { // Wait time is over, fire up the animation. timer -= WAIT_TIME; mode = Mode.Animate; // Start the anim at the current position... patrolStep++; if (patrolStep >= patrol.Length) { patrolStep = 0; } dweller.AnimateToCell(patrol[patrolStep], ANIMATE_TIME); } else if (mode == Mode.Animate && timer >= ANIMATE_TIME) { timer -= ANIMATE_TIME; mode = Mode.Wait; // Make sure we are on the ground once the animation ends. Vector3 newPosition = gameObject.transform.position; newPosition.y = 0; gameObject.transform.position = newPosition; } if (mode == Mode.Animate) { float progress = timer / ANIMATE_TIME; // Compute a parabolic jump animation. Vector3 newPosition = gameObject.transform.position; newPosition.y = ANIMATION_HEIGHT * ParabolicCurve(progress); gameObject.transform.position = newPosition; } }