private void RandomizeAttack() { int thonk; thonk = Random.Range(0, 10); if (player.transform.position.y > 4) { state = ArmStates.slashWalking; } else { if (thonk < 7) { state = ArmStates.spinning; animator.SetInteger("Attack", 1); cooldownTimer = 5; } else { state = ArmStates.slashWalking; } } }
// Update is called once per frame void Update() { float width = (float)health / (float)200; healthbar.rectTransform.sizeDelta = new Vector2(width * 600, 40); switch (state) { case ArmStates.walking: direction = (player.transform.position - transform.position).normalized; direction.y = 0; gameObject.transform.position += direction * speed * Time.deltaTime; gameObject.transform.LookAt(transform.position + direction); if ((player.transform.position - transform.position).magnitude <= 15) { RandomizeAttack(); } break; case ArmStates.slashWalking: //state = ArmStates.spinning; direction = (player.transform.position - transform.position).normalized; direction.y = 0; gameObject.transform.position += direction * speed * 1.5f * Time.deltaTime; gameObject.transform.LookAt(transform.position + direction); if ((player.transform.position - transform.position).magnitude <= 7) { state = ArmStates.slashing; transform.Rotate(0, -15, 0); cooldownTimer = 1; animator.SetInteger("Attack", 2); } break; case ArmStates.slashing: //animation play cooldownTimer -= Time.deltaTime; if (cooldownTimer <= 0) { state = ArmStates.tired; cooldownTimer = 3; animator.SetInteger("Attack", 0); } break; case ArmStates.spinning: //run spinning animation direction = (player.transform.position - transform.position).normalized; direction.y = 0; gameObject.transform.position += direction * speed * Time.deltaTime; gameObject.transform.Rotate(0, Time.deltaTime * 720, 0); cooldownTimer -= Time.deltaTime; if (cooldownTimer <= 0) { state = ArmStates.tired; cooldownTimer = 3; animator.SetInteger("Attack", 0); } break; case ArmStates.tired: cooldownTimer -= Time.deltaTime; if (cooldownTimer <= 0) { state = ArmStates.walking; } break; } }