private void StartGrab() { isGrabbing = false; if (isHolding) { return; } foreach (Vector2 direction in Enum.GetValues(typeof(CardinalDirections)).Cast <CardinalDirections>().Select(c => c.AsVector2())) { Vector2 grabPosition = transform.position2D() + direction; Collider2D collide = Physics2D.OverlapPoint(grabPosition); if (collide == null) { continue; } IGrabbable grabbable = collide.GetComponent(typeof(IGrabbable)) as IGrabbable; if (grabbable != null && grabbable.CanGrab()) { stepState.GrabPosition = grabPosition; isGrabbing = true; Rock = ((GameObject)GameObject.Instantiate(RockPrefab, grabPosition, Quaternion.identity)).transform; grabbable.OnGrab(); break; } } }
private void GrabGrabbable(IGrabbable grabbable) { _grabSlots.Add(grabbable); grabbable.OnGrab(_playerContext); grabbable.Transform.parent = transform; grabbable.Rigidbody.isKinematic = true; grabbable.GrabCoroutine = StartCoroutine(TweenUtil.EaseTransformToPoint(grabbable.Transform, _grabPivot, _grabEaseModifier, GRAB_PIVOT_SNAP_THRESHOLD)); }