IEnumerator Shoot() { RaycastHit2D hitReg = Physics2D.Raycast(firepoint.position, firepoint.up); if (hitReg) { Player_Health health = hitReg.transform.GetComponent <Player_Health>(); if (health != null) { health.TakeDamage(damage); } line.SetPosition(0, firepoint.position); line.SetPosition(1, hitReg.point); } else { line.SetPosition(0, firepoint.position); line.SetPosition(1, firepoint.position + firepoint.up * 100); } line.enabled = true; yield return(new WaitForSeconds(0.02f)); line.enabled = false; }
void Attack() { timer = 0f; if (playerHealth.currentHealth > 0) { playerHealth.TakeDamage(attackDamage); } }
/// <summary> /// Called to take damage /// </summary> /// <param name="damageTaken"></param> public void TakeDamage(float damageTaken) { // Initial damage deduction _playerHealth.TakeDamage(damageTaken); // Check if the player is dead _isDead = _playerHealth.CheckDead(); }
void Attack() { // Reset the timer. timer = 0f; if (playerHealth.cur_health > 0) { playerHealth.TakeDamage(attackDamage); } }
void Attack() { if (Time.time > attackCooldown) { playerhealth.TakeDamage(damage); myAnimator.SetTrigger("Attack"); attackCooldown = Time.time + delayBetweenAttacks; //audioSource.PlayOneShot(AttackSound); } }
private void OnTriggerEnter2D(Collider2D collision) { Player_Health player = collision.GetComponent <Player_Health>(); if (player != null) { player.health = player.maxHealth; player.TakeDamage(0, false); Destroy(gameObject); } }
void Attack() { // Reset the timer. timer = 0f; // If the player has health to lose... if (playerHealth.currentHealth > 0) { // ... damage the player. playerHealth.TakeDamage(attackDamage); } }
//called after animation void EnableAttack() { canAttack = true; //attacking = false; //rB.isKinematic = false; anim.SetBool("Attack", false); if (Vector3.Distance(player.transform.position, transform.position) <= attackDistance && canAttack == true) { Player_Health playerHealth = player.GetComponent <Player_Health>(); playerHealth.TakeDamage(attackDamage); } }
void Attack() { // Reset the timer. timer = 0f; // If the player has health to lose... if (playerHealth.currentHealth > 0) { // ... damage the player. playerHealth.TakeDamage(attackDamage); if (gameObject.tag == "Banana") { Destroy(this.gameObject); } } }
void OnTriggerEnter2D(Collider2D hitInfo) { // Debug.Log(hitInfo + "Hello"); Player_Health health = hitInfo.GetComponent <Player_Health>(); Wall wall = hitInfo.GetComponent <Wall>(); if (health != null) { health.TakeDamage(damage); } if (wall != null) { Destroy(gameObject); } Destroy(gameObject); }
void OnTriggerEnter2D(Collider2D hitInfo) { if (hitInfo.tag == "Enemy" || hitInfo.tag == "Ignore") { return; } Player_Health player = hitInfo.GetComponent <Player_Health>(); if (player != null) { player.TakeDamage(damage, true); } Debug.Log("Tag " + hitInfo.tag); Debug.Log(hitInfo.name); Instantiate(impactEffect, transform.position, transform.rotation); Destroy(gameObject); }
private void Update() { // Don't try to merge the two ifs below. It doesn't make sense, but it doensn't work. if (rBody.velocity.y < 0f) { animator.SetTrigger("MidAir"); } else { animator.ResetTrigger("MidAir"); } if (rBody.velocity.y <= 0f) { rising = false; } if (rBody.velocity.x > 0.001f) { sRenderer.flipX = false; animator.SetBool("Moving", true); } else if (rBody.velocity.x < -0.001f) { sRenderer.flipX = true; animator.SetBool("Moving", true); } else { animator.SetBool("Moving", false); } // Walk sideways float horizontalInput = Input.GetAxis("Horizontal"); float horizontalInputRaw = Input.GetAxisRaw("Horizontal"); RunningCheck((int)horizontalInputRaw); float movementSpeed; isClimbing = false; if (isRunning) { movementSpeed = Mathf.Lerp(Mathf.Abs(rBody.velocity.x), rollSpeed, acceleration); } else { movementSpeed = speed; } if (!wallJumping) { int runningDirection = rBody.velocity.x > 0 ? 1 : rBody.velocity.x < 0 ? -1 : 0; ramp = runDirection == 1 ? rampRight : runDirection == -1 ? rampLeft : false; if (isOnWall && isGrounded && !jumping && ramp) { isClimbing = true; int yDirection = wallSide == horizontalInputRaw ? 1 : -1; if (runningDirection != horizontalInputRaw) { rBody.velocity = Vector2.Lerp(rBody.velocity, new Vector2(horizontalInput, yDirection) * speed, acceleration); } else { rBody.velocity = new Vector2(horizontalInput, yDirection) * movementSpeed; } } else if (runningDirection != horizontalInputRaw) { movementSpeed = Mathf.Lerp(rBody.velocity.x, horizontalInput * speed, acceleration); rBody.velocity = new Vector2(movementSpeed, rBody.velocity.y); } else { rBody.velocity = new Vector2(horizontalInput * movementSpeed, rBody.velocity.y); } } else { rBody.velocity = Vector2.Lerp(rBody.velocity, new Vector2(horizontalInput * movementSpeed, rBody.velocity.y), Time.deltaTime); } if (isOnWall && !isClimbing) { isRunning = false; animator.SetBool("Running", false); preparingRun = false; } // Wall and Ground detenction isGrounded = Physics2D.OverlapCircle(groundDetector.position, groundDetectorRadius); animator.SetBool("Grounded", isGrounded); isOnLeftWall = Physics2D.OverlapCircle(wallDetectorL.position, wallDetectorRadius); isOnRightWall = Physics2D.OverlapCircle(wallDetectorR.position, wallDetectorRadius); rampLeft = !Physics2D.OverlapCircle(rampDetectorL.position, wallDetectorRadius); rampRight = !Physics2D.OverlapCircle(rampDetectorR.position, wallDetectorRadius); isOnWall = isOnLeftWall || isOnRightWall; wallSide = !isOnWall ? 0 : isOnLeftWall ? -1 : 1; if (isGrounded) { animator.SetTrigger("Fall"); } else { animator.ResetTrigger("Fall"); } // Checks if should slide if (wallSide == horizontalInputRaw) { isSliding = true; CancelInvoke(nameof(StopSliding)); } else if (isSliding) { Invoke(nameof(StopSliding), stopSlidingTime); } // Wall slide if (isOnWall && !isGrounded && isSliding) { if (!rising) { rBody.velocity = new Vector2(rBody.velocity.x, -slideSpeed); } else { rBody.velocity = Vector2.Lerp(rBody.velocity, new Vector2(rBody.velocity.x, -slideSpeed), Time.deltaTime); } animator.SetBool("Sliding", true); animator.SetBool("Running", false); isRunning = false; if (isOnLeftWall) { sRenderer.flipX = false; } else { sRenderer.flipX = true; } } else { animator.SetBool("Sliding", false); } // Jump if (Input.GetKeyDown(KeyCode.Z)) { if (isGrounded) { StartCoroutine(SetJumpFlag()); rBody.velocity = new Vector2(rBody.velocity.x, jumpForce); if (!isRunning) { animator.SetTrigger("Jump"); } tickSource.Play(); if (rBody.velocity.y > 0f) { rising = true; } } else if (isOnWall && isSliding) { Vector2 jumpDirection = new Vector2(wallJumpDirection.x * -wallSide, wallJumpDirection.y); rBody.velocity = jumpDirection.normalized * wallJumpForce; StartCoroutine(SetWallJumpFlag()); animator.ResetTrigger("MidAir"); tickSource.Play(); if (!isRunning) { animator.SetTrigger("Jump"); } animator.SetBool("Sliding", false); if (rBody.velocity.y > 0f) { rising = true; } } } // Open/Close eyes if (Input.GetKeyDown(KeyCode.X) || !isRunning) { EyeCameraController.instance.OpenEyes(); } else if (Input.GetKeyUp(KeyCode.X)) { if (isRunning) { EyeCameraController.instance.CloseEyes(); } } // Roll damage if (isRunning && isGrounded && !EyeCameraController.instance.isClosed) { health.TakeDamage(rollDamage); } ApplyJumpGravityModifiers(); }
void Attack() { playerhealth.TakeDamage(damage); }