void FixedUpdate() { if (Time.time - timeCounter >= secondsBetweenHits) { bool breakAll = false; Collider2D[] colliders = Physics2D.OverlapAreaAll(startRaycastPoint.position, endRaycastPoint.position); if (colliders != null && colliders.Length != 0) { foreach (Collider2D collider in colliders) { if (tags != null & tags.Length != 0) { foreach (string tag in tags) { if (collider.CompareTag(tag)) { hitting = true; dmgDealer.ApplyDamageOnce(collider.gameObject); thisRigidBody.velocity = new Vector2(0, 0); timeCounter = Time.time; breakAll = true; break; } } } if (breakAll) { break; } } } } thisAnimator.SetBool("Hook", hitting); if (thisAnimator.GetCurrentAnimatorStateInfo(0).IsTag("Attack")) { thisSpriteRenderer.sortingLayerName = "Character"; gameObject.GetComponent <Rigidbody2D>().velocity = new Vector2(0, 0); } else { thisSpriteRenderer.sortingLayerName = "EnemyRobot"; } if (!hitting && !thisAnimator.GetCurrentAnimatorStateInfo(0).IsTag("Attack") && (Mathf.Abs(thisRigidBody.velocity.x) != xVelocity)) { if (transform.localScale.x >= 0) { thisRigidBody.velocity = new Vector2(xVelocity, 0); } else { thisRigidBody.velocity = new Vector2(-xVelocity, 0); } } hitting = false; }
private void SteppingOnEnemies() { foreach (Collider2D collider in Physics2D.OverlapBoxAll(new Vector2(charCollider.bounds.min.x, charCollider.bounds.min.y), new Vector2(charCollider.bounds.size.x, -deviationYToCountForProperSteppingOnEnemies), LayerMask.GetMask(enemyLayers))) { if (!hitTargets.Contains(collider.gameObject) && collider.gameObject.CompareTag("Enemy") && !collider.isTrigger && characterRigidBody.velocity.y < 0 && charCollider.bounds.min.y > collider.bounds.max.y - deviationYToCountForProperSteppingOnEnemies) { hitTargets.Add(collider.gameObject); dmgDealer.ApplyDamageOnce(collider.gameObject); } } }