Ejemplo n.º 1
0
 private void OnCollisionEnter2D(Collision2D collidedWith)
 {
     if (collidedWith.gameObject.MatchesTagMask <ElementTags>(elementTags))
     {
         _moveRigidbody.Flip();
     }
 }
Ejemplo n.º 2
0
    private void LateUpdate()
    {
        var sensorPos = transform.position;
        var offset    = _collider.bounds.size.x / 2f;

        offset      *= (_spriteRenderer.flipX ^ initialDirectionIsLeft) ? -1f : 1f;
        sensorPos.x += offset;
        var rayCastHit = Physics2D.Raycast(sensorPos, Vector2.down, maxDistance, _layerMask);

        Debug.DrawRay(sensorPos, Vector2.down * maxDistance, Color.green);
        var hitCollider = rayCastHit.collider;

        if (hitCollider == null)
        {
            _moveRigidbody.Flip();
        }
    }