void OnCollisionStay2D(Collision2D other) { if (other.gameObject.layer == 12) { MoveableBlockController block = other.gameObject.GetComponent <MoveableBlockController>(); bool pushing = Input.GetAxisRaw("Horizontal") == block.input.x; anim.SetBool("pushing", pushing); } }
void OnCollisionStay2D(Collision2D other) { if (other.gameObject.layer == 8) // && Input.GetButton("Fire1")) { Vector2 colliderRange = GetComponent <Collider2D>().bounds.extents; Vector2 distance = other.transform.position - transform.position; if (Mathf.Abs(distance.y) < colliderRange.y && Mathf.Abs(distance.x) < colliderRange.x + movingRange) { bool forward = distance.x < 0; MoveAlongX(forward); } } if (other.gameObject.layer == 12) { MoveableBlockController blockController = other.gameObject.GetComponent <MoveableBlockController>(); if (blockController != null) { blockController.input.x = input.x; } } }