private bool IsWall(bool ahead) { var point = transform.position; RaycastHit2D hit; if (ahead) { var horizontalVector = GetDirectionVector(point, new Vector2(point.x * -1, point.y)); hit = Physics2D.Raycast(point, horizontalVector); } else { var horizontalVector = GetDirectionVector(point, new Vector2(point.x, point.y)); hit = Physics2D.Raycast(point, horizontalVector); } if (hit && hit.collider && GroundChecker.GetWhatIsGround() == (GroundChecker.GetWhatIsGround() | (1 << hit.collider.gameObject.layer))) { return(true); } return(false); }
private bool IsGround(bool ahead) { if (!_facingComponent) { Debug.LogError("Object has no facing component."); } var pos = transform.position; var offset = _facing == 0 ? -1 : 1; Vector2 point; Vector2 downVector; if (ahead) { point = new Vector2(pos.x + offset - groundAlert_distance, 0); downVector = new Vector2(pos.x + offset - groundAlert_distance, -1 * 20); } else { point = new Vector2(pos.x + offset + groundAlert_distance, 0); downVector = new Vector2(pos.x + offset + groundAlert_distance, -1 * 20); } var hit = Physics2D.Raycast(point, GetDirectionVector(point, downVector)); Debug.DrawRay(point, GetDirectionVector(point, downVector)); if (!hit || !hit.collider || GroundChecker.GetWhatIsGround() != (GroundChecker.GetWhatIsGround() | (1 << hit.collider.gameObject.layer))) { return(false); } return(true); }