private void OnTriggerEnter2D(Collider2D collision) { if (collision.gameObject.CompareTag("Sword") && gameObject.tag != "Dying") { gamePad.SetVibration(100, 100, 0.15f); gameObject.tag = "Dying"; gameObject.GetComponent <Animator>().Play("Die"); Destroy(Instantiate(BloodParticle, transform.position, Quaternion.identity), 1.0f); camShake.Shakee(0.1f, 0.1f); gameObject.GetComponent <AudioSource>().Play(); Destroy(gameObject, 0.8f); } }
void OnCollisionEnter2D(Collision2D collision) { if (collision.gameObject.layer == 17) { isGrounded = true; Destroy(Instantiate(FallingParticle, new Vector3(transform.position.x, transform.position.y - 1, transform.position.z), Quaternion.identity), 2.5f); gameObject.GetComponent <AudioSource>().Play(); { gamePad.SetVibration(100, 100, 0.15f); camShake.Shakee(0.1f, 0.1f); } } }
void Update() { if (bossDM_Point) { transform.position = Vector3.MoveTowards(transform.position, DMPoint.position, Time.deltaTime * 30); if (transform.position == DMPoint.position) { bossDM_Point = false; bossDM_attack = true; bossAnim.Play("DM"); } } if (bossDM_attack) { foreach (KeyValuePair <GameObject, Vector3> entry in fireballArray) { if (entry.Key != null) { entry.Key.transform.position = Vector3.MoveTowards(entry.Key.transform.position, entry.Value, Time.deltaTime * fireballSpeed); if (entry.Key.transform.position == entry.Value) { Destroy(entry.Key); } } } if (fireballArray.Count == 0 && isReturningSpawn) { bossDM_attack = false; } } if (!isRushing || !isReturningSpawn) { FlipTowardsPlayer(); } if (upPlateform) { plateform.transform.GetChild(0).gameObject.GetComponentInChildren <BoxCollider2D>().enabled = true; plateform.transform.position = Vector3.MoveTowards(plateform.transform.position, upPlateformPos, Time.deltaTime * 9); } else { plateform.transform.GetChild(0).gameObject.GetComponentInChildren <BoxCollider2D>().enabled = false; plateform.transform.position = Vector3.MoveTowards(plateform.transform.position, downPlateformPos, Time.deltaTime * 9); } if (isReturningSpawn) { FlipRight(); transform.position = Vector3.MoveTowards(transform.position, SpawnPoint.position, Time.deltaTime * returnToSpawnSpeed); if (transform.position == SpawnPoint.position) { FlipLeft(); if (upPlateform) { upPlateform = false; } isReturningSpawn = false; if (isAgressive) { StartCoroutine(chooseAttack(timeBetweenAttack)); } } } if (isRushing) { FlipLeft(); transform.position = Vector3.MoveTowards(transform.position, ForwardPoint.position, Time.deltaTime * moveSpeedForward); if (transform.position == ForwardPoint.position) { camShake.Shakee(0.1f, 0.1f); Audio.clip = StompSound; Audio.Play(); FlipRight(); isRushing = false; returnToSpawn(); } } JumpingAttackPhysics(); DivingAttackPhysics(); }
void HandleMovement() { if (!Anim.GetCurrentAnimatorStateInfo(0).IsName("AttackMoving") && !Anim.GetCurrentAnimatorStateInfo(0).IsName("Attack")) { if (Input.GetButtonDown("Attack")) { if (Input.GetAxisRaw("Horizontal") != 0 && isGrounded == true) { Anim.Play("AttackMoving"); } else { Anim.Play("Attack"); } if (haveSword == true) { attackSoundSword.Play(); } if (unarmed == true) { attackSoundUnarmed.Play(); } } else if (dead == false) { if (Input.GetAxisRaw("Horizontal") == 0 && isGrounded == true) { Anim.Play("Idle"); } else if (Input.GetAxisRaw("Horizontal") != 0 && isGrounded == true) { Anim.Play("Run"); } else if (isGrounded == false) { Anim.Play("Jump"); } } } if (Input.GetAxisRaw("Horizontal") > 0) { transform.transform.Translate(Vector2.right * Input.GetAxisRaw("Horizontal") * moveSpeed * Time.deltaTime); if (Input.GetAxisRaw("Horizontal") > 0) { Flip(false); } } else if (Input.GetAxisRaw("Horizontal") < 0) { transform.transform.Translate(Vector2.right * Input.GetAxisRaw("Horizontal") * moveSpeed * Time.deltaTime); if (Input.GetAxisRaw("Horizontal") < 0) { Flip(true); } } if ((Input.GetButtonDown("Dash") || Input.GetAxis("Dash") > 0) && isGrounded == false && dashCount == 0) { gamePad.SetVibration(100, 100, 0.15f); isJumping = false; Destroy(Instantiate(dashEffect, transform.position, Quaternion.identity), 1.0f); DashSound.Play(); dashCount = 1; moveSpeed = 0; rigidBody2D.velocity = new Vector2(0, 0); if (right == true) { rigidBody2D.velocity = Vector2.right * 20; } if (left == true) { rigidBody2D.velocity = Vector2.left * 20; } rigidBody2D.gravityScale = 0.0f; camShake.Shakee(camShakeAmount, 0.1f); (CameraObject.GetComponent("MotionBlur") as MonoBehaviour).enabled = true; StartCoroutine(DashGravity(0.20f)); } if (isGrounded == true && Input.GetButtonDown("Jump")) { Anim.Play("Jump"); if (inWater == false) { Destroy(Instantiate(JumpParticle, new Vector3(transform.position.x, transform.position.y - 0.6f, transform.position.z), Quaternion.identity), 1.0f); } isJumping = true; jumpTimeCounter = jumpTime; rigidBody2D.velocity = new Vector2(rigidBody2D.velocity.x, 1 * jumpSpeed); } if (Input.GetButton("Jump") && isJumping == true) { if (jumpTimeCounter > 0) { rigidBody2D.velocity = new Vector2(rigidBody2D.velocity.x, 1 * jumpSpeed); jumpTimeCounter -= Time.deltaTime * 2; } else { isJumping = false; } } if (Input.GetButtonUp("Jump")) { isJumping = false; } }