public IEnumerator ReceiveDamage() { currInvulframe = 0.0f; isInvul = true; --bosslife; gc.UpdateBossHealth(bosslife); if (bosslife <= 0) { currState = MikoState.DEAD; } while (currInvulframe < invulFrameMax) { spriteRenderer.color = Color.red; yield return(new WaitForSeconds(0.1f)); currInvulframe += 0.1f; spriteRenderer.color = Color.black; yield return(new WaitForSeconds(0.05f)); currInvulframe += 0.05f; } spriteRenderer.color = Color.white; isInvul = false; }
// Start is called before the first frame update void Start() { animator = GetComponent <Animator>(); prevNumber = 1; currState = MikoState.SPIN; gc = GameObject.Find("GameController").GetComponent <GameController>(); gc.UpdateBossHealth(bosslife); }
IEnumerator Throw() { int i; while (!reached) { if (!rightside) { transform.position = Vector2.MoveTowards(transform.position, leftSide.position + new Vector3(0f, -4.5f, 0f), floatSpeed * Time.deltaTime); if (Vector3.Distance(transform.position, leftSide.position + new Vector3(0f, -4.5f, 0f)) < 0.1f) { reached = true; } } else { transform.position = Vector2.MoveTowards(transform.position, rightSide.position + new Vector3(0f, -4.5f, 0f), floatSpeed * Time.deltaTime); if (Vector3.Distance(transform.position, rightSide.position + new Vector3(0f, -4.5f, 0f)) < 0.1f) { reached = true; } } yield return(null); } reached = false; yield return(new WaitForSeconds(2f)); animator.Play("MikoTable"); for (i = 0; i < 8; ++i) { float ranX = Random.Range(5f, 9f); if (rightside) { ranX = -ranX; } float ranY = Random.Range(5f, 13f); Vector2 movement = new Vector3(ranX, ranY, 0f); var temp = Instantiate(tablePrefab, transform.position, Quaternion.identity); temp.GetComponent <Rigidbody2D>().velocity = movement; yield return(new WaitForSeconds(0.50f)); } animator.CrossFade("MikoIdle", 0.1f); yield return(new WaitForSeconds(3f)); if (currState != MikoState.DEAD) { currState = MikoState.SPIN; } yield return(0); }
// Update is called once per frame void Update() { if (Input.GetKeyDown(KeyCode.E)) { StartCoroutine(Spin()); } if (Input.GetKeyDown(KeyCode.R)) { StartCoroutine(Throw()); } if (Input.GetKeyDown(KeyCode.T)) { StartCoroutine(RotateCamera()); } switch (currState) { case MikoState.IDLE: break; case MikoState.DANMAKU: Danmaku(); break; case MikoState.ROTATECAM: StartCoroutine(RotateCamera()); prevState = MikoState.ROTATECAM; currState = MikoState.IDLE; break; case MikoState.TABLE: StartCoroutine(Throw()); prevState = MikoState.TABLE; currState = MikoState.IDLE; break; case MikoState.SPIN: StartCoroutine(Spin()); currState = MikoState.DANMAKU; break; case MikoState.DEAD: if (!dead) { StopAllCoroutines(); StartCoroutine(PlayDead()); } break; } }
IEnumerator RotateCamera() { int rand = Random.Range(1, 5); while (prevNumber == rand) { rand = Random.Range(1, 5); } switch (rand) { case 1: cam.CrossFade("CamNeutral", 0.2f); break; case 2: cam.CrossFade("CamRotate90", 0.2f); break; case 3: cam.CrossFade("CamRotate180", 0.2f); break; case 4: cam.CrossFade("CamRotate270", 0.2f); break; } prevNumber = rand; yield return(new WaitForSeconds(3f)); if (currState != MikoState.DEAD) { float randbool = Random.Range(0.0f, 1f); if (randbool <= 0.5f) { currState = MikoState.TABLE; } else { currState = MikoState.SPIN; } } yield return(0); }
IEnumerator Spin() { animator.Play("MikoSpin"); for (spinCount = 0; spinCount < 5; spinCount++) { float ranY = Random.Range(-2f, 1f); while (!reached) { if (rightside) { transform.position = Vector2.MoveTowards(transform.position, leftSide.position + new Vector3(0f, ranY, 0f), floatSpeed * Time.deltaTime); if (Vector3.Distance(transform.position, leftSide.position + new Vector3(0f, ranY, 0f)) < 0.1f) { reached = true; } } else { transform.position = Vector2.MoveTowards(transform.position, rightSide.position + new Vector3(0f, ranY, 0f), floatSpeed * Time.deltaTime); if (Vector3.Distance(transform.position, rightSide.position + new Vector3(0f, ranY, 0f)) < 0.1f) { reached = true; } } yield return(null); } rightside = !rightside; reached = false; } currState = MikoState.IDLE; animator.CrossFade("MikoIdle", 0.1f); spriteRenderer.flipX = !rightside; yield return(new WaitForSeconds(2f)); if (currState != MikoState.DEAD) { if (prevState == MikoState.ROTATECAM) { currState = MikoState.TABLE; } else { float randbool = Random.Range(0.0f, 1f); if (randbool <= 0.15f) { currState = MikoState.TABLE; } else { animator.Play("MikoFlip"); yield return(new WaitForSeconds(1f)); if (currState != MikoState.DEAD) { currState = MikoState.ROTATECAM; } } } } }