public void TurnTowards(InteractiveItem obj) { int d = transform.position.x < (obj.transform.position.x + obj.GetCenterOffset(heldItem).x) ? 1 : -1; ChangeDirection(d); ProcessDirectionAndScale(false); }
void ProcessInput(ref bool isHit, ref bool holding, ref Vector3 holdPosition, ref Vector3 worldPosition, ref InteractiveItem interactiveItem, ref bool justTouched) { justTouched = false; foreach (Touch touch in Input.touches) { holding = true; if (touch.phase == TouchPhase.Began) { justTouched = true; holdPosition = touch.position; startHoldPosition = holdPosition; } if (touch.phase == TouchPhase.Ended) { holding = false; holdPosition = touch.position; isHit = true; } } if (Input.GetButtonUp("Fire1")) { holding = false; holdPosition = Input.mousePosition; isHit = true; } if (Input.GetButtonDown("Fire1")) { justTouched = true; startHoldPosition = Input.mousePosition; } if (Input.GetButton("Fire1")) { holding = true; holdPosition = Input.mousePosition; } worldPosition = PersistentEngine.activeCamera.ScreenToWorldPoint(holdPosition); if (isHit) { Vector2 v = PersistentEngine.activeCamera.ScreenToWorldPoint(holdPosition); Collider2D[] col = Physics2D.OverlapPointAll(v); interactiveItem = null; if (col.Length > 0) { int lastLayer = int.MinValue; foreach (Collider2D c in col) { if (c.gameObject.layer == 10) { var elroyItem1 = c.gameObject.GetComponent <InteractiveItem>(); if (elroyItem1 != null && elroyItem1.enabled && elroyItem1.itemLayer > lastLayer) { lastLayer = elroyItem1.itemLayer; interactiveItem = elroyItem1; Vector3 posx = interactiveItem.transform.position + interactiveItem.GetCenterOffset(heldItem);// interactiveItem.collider2D.bounds.center;// + interactiveItem.transform.position; worldPosition = posx + interactiveItem.GetStoppingDistance(heldItem); } } } } } }