private void Rob() { if (!target) { state = StrangerState.Wander; return; } var targetHuman = target.GetComponent <Human>(); if (targetHuman == null || !DoesHumanHaveWoodILack(targetHuman)) { state = StrangerState.Wander; return; } SetReadyToShoot(true); if (Mathf.Abs(target.position.y - transform.position.y) > 0.05f) { var targetPosition = target.position; var transformPosition = transform.position; human.Move(new Vector2( Mathf.Sign(targetPosition.x - transformPosition.x) * 0.1f, Mathf.Sign(targetPosition.y - transformPosition.y) )); return; } human.Act(); }
private void Fight() { if (!target) { state = StrangerState.Wander; return; } var hittable = target.GetComponent <IHittable>(); if (hittable == null || !hittable.IsThreat()) { state = StrangerState.Wander; return; } SetReadyToShoot(true); if (Mathf.Abs(target.position.y - transform.position.y) > 0.05f) { var targetPosition = target.position; var transformPosition = transform.position; human.Move(new Vector2( Mathf.Sign(targetPosition.x - transformPosition.x) * 0.1f, Mathf.Sign(targetPosition.y - transformPosition.y) )); return; } human.Act(); }
private void Gather() { SetReadyToShoot(false); if (!target) { state = StrangerState.Wander; return; } Vector2 gatherDirection = target.position - transform.position; human.Move(gatherDirection.SkewDirection(5)); }
private void Update() { if (human.IsDead()) { return; } // Reduce amount of expensive calls if (Random.value > 0.9f) { state = GetCurrentState(); } switch (state) { case StrangerState.Gather: Gather(); break; case StrangerState.SeekBonfire: SeekBonfire(); break; case StrangerState.StartBonfire: human.Fire(); state = GetCurrentState(); break; case StrangerState.Fight: Fight(); break; case StrangerState.Rob: Rob(); break; case StrangerState.Flee: Flee(); break; case StrangerState.Wander: Wander(); break; default: throw new ArgumentOutOfRangeException(); } }