private void GenerateMagnets() { Bounds backgroundBounds = GetComponent <SpriteRenderer>().bounds; Vector2 backgroundSize = backgroundBounds.size; //Debug.Log(backgroundSize); Vector3 backgroundTopLeftCorner = backgroundBounds.center - new Vector3(backgroundBounds.extents.x, backgroundBounds.extents.y, 0.1f); Vector2 magnetSize = MagnetPrefab.GetComponent <SpriteRenderer>().bounds.size; //Debug.Log(magnetSize); int lineLength = (int)((backgroundSize.x - InterSpace) / (magnetSize.x + InterSpace)); int columnLength = (int)((backgroundSize.y - InterSpace) / (magnetSize.y + InterSpace)); //Debug.Log(lineLength + " ; " + columnLength); for (int i = 0; i < lineLength; ++i) { for (int j = 0; j < columnLength; ++j) { Vector3 position = new Vector3(i * (magnetSize.x + InterSpace) + magnetSize.x / 2 + InterSpace, j * (magnetSize.y + InterSpace) + magnetSize.y / 2 + InterSpace, 0) + backgroundTopLeftCorner; Instantiate <Magnet>(MagnetPrefab, position, Quaternion.identity, this.transform).Field = this; } } MagnetPrefab.transform.gameObject.SetActive(false); }
// CREATE MODE void createWith() { RaycastHit hit; if (Input.touchCount > 0) { if (Input.touchCount == 2) { foreach (Touch t in Input.touches) { if (rayLimit.Contains(t.position)) { Ray ray = Camera.main.ScreenPointToRay(t.position); touchPosition = t.position; switch (t.phase) { case TouchPhase.Began: if (t.fingerId == 0) { touchIndicatorOne.SetActive(true); } else if (t.fingerId == 1) { touchIndicatorTwo.SetActive(true); } if (Physics.Raycast(ray, out hit)) { if (t.fingerId == 0) { if (hit.transform.tag == "shape") { GameManager.instance.mfuncs.selectPiece(hit.transform.gameObject); grabbedObjectOne = hit.transform.gameObject; touch = Camera.main.ScreenToWorldPoint(new Vector3(touchPosition.x, touchPosition.y, Camera.main.transform.position.y - grabbedObjectOne.transform.position.y)); offset = grabbedObjectOne.transform.position - touch; } else if (hit.collider.tag == "contact") { if (!GameManager.instance.destroyJoint && !GameManager.instance.groundJoint) { GameManager.instance.mfuncs.selectPiece(hit.transform.gameObject.GetComponent <Magnet> ().LShape); grabbedObjectOne = hit.transform.gameObject; touch = Camera.main.ScreenToWorldPoint(new Vector3(touchPosition.x, touchPosition.y, Camera.main.transform.position.y - grabbedObjectOne.transform.position.y)); offset = grabbedObjectOne.transform.position - touch; } else if (GameManager.instance.destroyJoint) { GameManager.instance.mfuncs.selectPiece(hit.transform.gameObject.GetComponent <Magnet> ().LShape); grabbedObjectOne = hit.transform.gameObject; touch = Camera.main.ScreenToWorldPoint(new Vector3(touchPosition.x, touchPosition.y, Camera.main.transform.position.y - grabbedObjectOne.transform.position.y)); offset = grabbedObjectOne.transform.position - touch; GameManager.instance.mfuncs.removeJoint(grabbedObjectOne.GetComponent <PartnerJoint> ().partnerJoint); GameManager.instance.mfuncs.DestroyJoint(false); GameObject.Find("Joint Destroy Button").GetComponent <Image> ().sprite = GameManager.instance.destroyJointsOffImage; } else if (GameManager.instance.groundJoint) { Debug.Log("here"); GameManager.instance.mfuncs.selectPiece(hit.transform.gameObject.GetComponent <Magnet> ().LShape); grabbedObjectOne = hit.transform.gameObject; touch = Camera.main.ScreenToWorldPoint(new Vector3(touchPosition.x, touchPosition.y, Camera.main.transform.position.y - grabbedObjectOne.transform.position.y)); offset = grabbedObjectOne.transform.position - touch; GameManager.instance.mfuncs.connectJointToGround(grabbedObjectOne); GameManager.instance.mfuncs.groundJoint(false); GameObject.Find("Joint Ground Button").GetComponent <Image> ().sprite = GameManager.instance.groundJointOffImage; } } } else if (t.fingerId == 1) { if (hit.transform.tag == "shape") { GameManager.instance.mfuncs.selectPiece(hit.transform.gameObject); grabbedObjectTwo = hit.transform.gameObject; touch = Camera.main.ScreenToWorldPoint(new Vector3(touchPosition.x, touchPosition.y, Camera.main.transform.position.y - grabbedObjectTwo.transform.position.y)); offset = grabbedObjectTwo.transform.position - touch; } else if (hit.collider.tag == "contact") { if (!GameManager.instance.destroyJoint && !GameManager.instance.groundJoint) { GameManager.instance.mfuncs.selectPiece(hit.transform.gameObject.GetComponent <Magnet> ().LShape); grabbedObjectTwo = hit.transform.gameObject; touch = Camera.main.ScreenToWorldPoint(new Vector3(touchPosition.x, touchPosition.y, Camera.main.transform.position.y - grabbedObjectTwo.transform.position.y)); offset = grabbedObjectTwo.transform.position - touch; } else if (GameManager.instance.destroyJoint) { GameManager.instance.mfuncs.selectPiece(hit.transform.gameObject.GetComponent <Magnet> ().LShape); grabbedObjectOne = hit.transform.gameObject; touch = Camera.main.ScreenToWorldPoint(new Vector3(touchPosition.x, touchPosition.y, Camera.main.transform.position.y - grabbedObjectOne.transform.position.y)); offset = grabbedObjectOne.transform.position - touch; GameManager.instance.mfuncs.removeJoint(grabbedObjectOne.GetComponent <PartnerJoint> ().partnerJoint); GameManager.instance.mfuncs.DestroyJoint(false); GameObject.Find("Joint Destroy Button").GetComponent <Image> ().sprite = GameManager.instance.destroyJointsOffImage; } else if (GameManager.instance.groundJoint) { Debug.Log("here"); GameManager.instance.mfuncs.selectPiece(hit.transform.gameObject.GetComponent <Magnet> ().LShape); grabbedObjectOne = hit.transform.gameObject; touch = Camera.main.ScreenToWorldPoint(new Vector3(touchPosition.x, touchPosition.y, Camera.main.transform.position.y - grabbedObjectOne.transform.position.y)); offset = grabbedObjectOne.transform.position - touch; GameManager.instance.mfuncs.connectJointToGround(grabbedObjectOne); GameManager.instance.mfuncs.groundJoint(false); GameObject.Find("Joint Ground Button").GetComponent <Image> ().sprite = GameManager.instance.groundJointOffImage; } } } } { GameManager.instance.mfuncs.unselectAllPieces(); } break; case TouchPhase.Moved: if (t.fingerId == 0) { moveIndicator(touchIndicatorOne, t); if (grabbedObjectOne != null) { touch = Camera.main.ScreenToWorldPoint(new Vector3(touchPosition.x, touchPosition.y, Camera.main.transform.position.y - grabbedObjectOne.transform.position.y)); forceDirection = (touch + offset) - grabbedObjectOne.transform.position; Debug.DrawLine(grabbedObjectOne.transform.position, forceDirection, Color.red); grabbedObjectOne.GetComponent <Rigidbody> ().AddForce(forceDirection * GameManager.instance.parameters.forceMultiplier); } break; } else if (t.fingerId == 1) { moveIndicator(touchIndicatorTwo, t); if (grabbedObjectTwo != null) { touch = Camera.main.ScreenToWorldPoint(new Vector3(touchPosition.x, touchPosition.y, Camera.main.transform.position.y - grabbedObjectTwo.transform.position.y)); forceDirection = (touch + offset) - grabbedObjectTwo.transform.position; Debug.DrawLine(grabbedObjectTwo.transform.position, forceDirection, Color.green); grabbedObjectTwo.GetComponent <Rigidbody> ().AddForce(forceDirection * GameManager.instance.parameters.forceMultiplier); } break; } break; case TouchPhase.Stationary: if (t.fingerId == 0) { moveIndicator(touchIndicatorOne, t); if (grabbedObjectOne != null) { touch = Camera.main.ScreenToWorldPoint(new Vector3(touchPosition.x, touchPosition.y, Camera.main.transform.position.y - grabbedObjectOne.transform.position.y)); forceDirection = (touch + offset) - grabbedObjectOne.transform.position; Debug.DrawLine(grabbedObjectOne.transform.position, forceDirection, Color.red); grabbedObjectOne.GetComponent <Rigidbody> ().AddForce(forceDirection * GameManager.instance.parameters.forceMultiplier); } break; } else if (t.fingerId == 1) { moveIndicator(touchIndicatorTwo, t); if (grabbedObjectTwo != null) { touch = Camera.main.ScreenToWorldPoint(new Vector3(touchPosition.x, touchPosition.y, Camera.main.transform.position.y - grabbedObjectTwo.transform.position.y)); forceDirection = (touch + offset) - grabbedObjectTwo.transform.position; Debug.DrawLine(grabbedObjectTwo.transform.position, forceDirection, Color.green); grabbedObjectTwo.GetComponent <Rigidbody> ().AddForce(forceDirection * GameManager.instance.parameters.forceMultiplier); } break; } break; case TouchPhase.Ended: if (t.fingerId == 0) { touchIndicatorOne.SetActive(false); grabbedObjectOne = null; } else if (t.fingerId == 1) { touchIndicatorTwo.SetActive(false); grabbedObjectTwo = null; } break; } } else { if (t.fingerId == 0) { touchIndicatorOne.SetActive(false); grabbedObjectOne = null; } else if (t.fingerId == 1) { touchIndicatorTwo.SetActive(false); grabbedObjectTwo = null; } } } } else if (Input.touchCount == 1) { foreach (Touch t in Input.touches) { if (rayLimit.Contains(t.position)) { Ray ray = Camera.main.ScreenPointToRay(t.position); touchPosition = t.position; switch (t.phase) { case TouchPhase.Began: if (t.fingerId == 0) { touchIndicatorOne.SetActive(true); } else if (t.fingerId == 1) { touchIndicatorTwo.SetActive(true); } if (Physics.Raycast(ray, out hit)) { if (t.fingerId == 0) { if (hit.transform.tag == "shape") { GameManager.instance.mfuncs.selectPiece(hit.transform.gameObject); grabbedObjectOne = hit.transform.gameObject; touch = Camera.main.ScreenToWorldPoint(new Vector3(touchPosition.x, touchPosition.y, Camera.main.transform.position.y - grabbedObjectOne.transform.position.y)); offset = grabbedObjectOne.transform.position - touch; } else if (hit.collider.tag == "contact") { if (!GameManager.instance.destroyJoint && !GameManager.instance.groundJoint) { GameManager.instance.mfuncs.selectPiece(hit.transform.gameObject.GetComponent <Magnet> ().LShape); grabbedObjectOne = hit.transform.gameObject; touch = Camera.main.ScreenToWorldPoint(new Vector3(touchPosition.x, touchPosition.y, Camera.main.transform.position.y - grabbedObjectOne.transform.position.y)); offset = grabbedObjectOne.transform.position - touch; } else if (GameManager.instance.destroyJoint) { GameManager.instance.mfuncs.selectPiece(hit.transform.gameObject.GetComponent <Magnet> ().LShape); grabbedObjectOne = hit.transform.gameObject; touch = Camera.main.ScreenToWorldPoint(new Vector3(touchPosition.x, touchPosition.y, Camera.main.transform.position.y - grabbedObjectOne.transform.position.y)); offset = grabbedObjectOne.transform.position - touch; GameManager.instance.mfuncs.removeJoint(grabbedObjectOne.GetComponent <PartnerJoint> ().partnerJoint); GameManager.instance.mfuncs.DestroyJoint(false); GameObject.Find("Joint Destroy Button").GetComponent <Image> ().sprite = GameManager.instance.destroyJointsOffImage; } else if (GameManager.instance.groundJoint) { Debug.Log("here"); GameManager.instance.mfuncs.selectPiece(hit.transform.gameObject.GetComponent <Magnet> ().LShape); grabbedObjectOne = hit.transform.gameObject; touch = Camera.main.ScreenToWorldPoint(new Vector3(touchPosition.x, touchPosition.y, Camera.main.transform.position.y - grabbedObjectOne.transform.position.y)); offset = grabbedObjectOne.transform.position - touch; GameManager.instance.mfuncs.connectJointToGround(grabbedObjectOne); GameManager.instance.mfuncs.groundJoint(false); GameObject.Find("Joint Ground Button").GetComponent <Image> ().sprite = GameManager.instance.groundJointOffImage; } } } else if (t.fingerId == 1) { if (hit.transform.tag == "shape") { GameManager.instance.mfuncs.selectPiece(hit.transform.gameObject); grabbedObjectTwo = hit.transform.gameObject; touch = Camera.main.ScreenToWorldPoint(new Vector3(touchPosition.x, touchPosition.y, Camera.main.transform.position.y - grabbedObjectTwo.transform.position.y)); offset = grabbedObjectTwo.transform.position - touch; } else if (hit.collider.tag == "contact") { if (!GameManager.instance.destroyJoint && !GameManager.instance.groundJoint) { GameManager.instance.mfuncs.selectPiece(hit.transform.gameObject.GetComponent <Magnet> ().LShape); grabbedObjectTwo = hit.transform.gameObject; touch = Camera.main.ScreenToWorldPoint(new Vector3(touchPosition.x, touchPosition.y, Camera.main.transform.position.y - grabbedObjectTwo.transform.position.y)); offset = grabbedObjectTwo.transform.position - touch; } else if (GameManager.instance.destroyJoint) { GameManager.instance.mfuncs.selectPiece(hit.transform.gameObject.GetComponent <Magnet> ().LShape); grabbedObjectOne = hit.transform.gameObject; touch = Camera.main.ScreenToWorldPoint(new Vector3(touchPosition.x, touchPosition.y, Camera.main.transform.position.y - grabbedObjectOne.transform.position.y)); offset = grabbedObjectOne.transform.position - touch; GameManager.instance.mfuncs.removeJoint(grabbedObjectOne.GetComponent <PartnerJoint> ().partnerJoint); GameManager.instance.mfuncs.DestroyJoint(false); GameObject.Find("Joint Destroy Button").GetComponent <Image> ().sprite = GameManager.instance.destroyJointsOffImage; } else if (GameManager.instance.groundJoint) { Debug.Log("here"); GameManager.instance.mfuncs.selectPiece(hit.transform.gameObject.GetComponent <Magnet> ().LShape); grabbedObjectOne = hit.transform.gameObject; touch = Camera.main.ScreenToWorldPoint(new Vector3(touchPosition.x, touchPosition.y, Camera.main.transform.position.y - grabbedObjectOne.transform.position.y)); offset = grabbedObjectOne.transform.position - touch; GameManager.instance.mfuncs.connectJointToGround(grabbedObjectOne); GameManager.instance.mfuncs.groundJoint(false); GameObject.Find("Joint Ground Button").GetComponent <Image> ().sprite = GameManager.instance.groundJointOffImage; } } } } else { GameManager.instance.mfuncs.unselectAllPieces(); } break; case TouchPhase.Moved: if (t.fingerId == 0) { moveIndicator(touchIndicatorOne, t); if (grabbedObjectOne != null) { touch = Camera.main.ScreenToWorldPoint(new Vector3(touchPosition.x, touchPosition.y, Camera.main.transform.position.y - grabbedObjectOne.transform.position.y)); forceDirection = (touch + offset) - grabbedObjectOne.transform.position; Debug.DrawLine(grabbedObjectOne.transform.position, forceDirection, Color.red); grabbedObjectOne.GetComponent <Rigidbody> ().AddForce(forceDirection * GameManager.instance.parameters.forceMultiplier); } break; } else if (t.fingerId == 1) { moveIndicator(touchIndicatorTwo, t); if (grabbedObjectTwo != null) { touch = Camera.main.ScreenToWorldPoint(new Vector3(touchPosition.x, touchPosition.y, Camera.main.transform.position.y - grabbedObjectTwo.transform.position.y)); forceDirection = (touch + offset) - grabbedObjectTwo.transform.position; Debug.DrawLine(grabbedObjectTwo.transform.position, forceDirection, Color.green); grabbedObjectTwo.GetComponent <Rigidbody> ().AddForce(forceDirection * GameManager.instance.parameters.forceMultiplier); } break; } break; case TouchPhase.Stationary: if (t.fingerId == 0) { moveIndicator(touchIndicatorOne, t); if (grabbedObjectOne != null) { touch = Camera.main.ScreenToWorldPoint(new Vector3(touchPosition.x, touchPosition.y, Camera.main.transform.position.y - grabbedObjectOne.transform.position.y)); forceDirection = (touch + offset) - grabbedObjectOne.transform.position; Debug.DrawLine(grabbedObjectOne.transform.position, forceDirection, Color.red); grabbedObjectOne.GetComponent <Rigidbody> ().AddForce(forceDirection * GameManager.instance.parameters.forceMultiplier); } break; } else if (t.fingerId == 1) { moveIndicator(touchIndicatorTwo, t); if (grabbedObjectTwo != null) { touch = Camera.main.ScreenToWorldPoint(new Vector3(touchPosition.x, touchPosition.y, Camera.main.transform.position.y - grabbedObjectTwo.transform.position.y)); forceDirection = (touch + offset) - grabbedObjectTwo.transform.position; Debug.DrawLine(grabbedObjectTwo.transform.position, forceDirection, Color.green); grabbedObjectTwo.GetComponent <Rigidbody> ().AddForce(forceDirection * GameManager.instance.parameters.forceMultiplier); } break; } break; case TouchPhase.Ended: if (t.fingerId == 0) { touchIndicatorOne.SetActive(false); grabbedObjectOne = null; } else if (t.fingerId == 1) { touchIndicatorTwo.SetActive(false); grabbedObjectTwo = null; } break; } } else { if (t.fingerId == 0) { touchIndicatorOne.SetActive(false); grabbedObjectOne = null; } else if (t.fingerId == 1) { touchIndicatorTwo.SetActive(false); grabbedObjectTwo = null; } } } } } else { foreach (GameObject L in GameManager.instance.config.configuration) { L.GetComponent <Rigidbody> ().velocity = new Vector3(0, 0, 0); L.GetComponent <Rigidbody> ().angularVelocity = new Vector3(0, 0, 0); foreach (GameObject Magnet in L.GetComponent <LShape>().allMagnets) { Magnet.GetComponent <Rigidbody>().velocity = new Vector3(0, 0, 0); Magnet.GetComponent <Rigidbody>().angularVelocity = new Vector3(0, 0, 0); } } } }
void playWith() { RaycastHit hit; if (Input.touchCount > 0) { if (Input.touchCount == 2) { foreach (Touch t in Input.touches) { Ray ray = Camera.main.ScreenPointToRay(t.position); touchPosition = t.position; switch (t.phase) { case TouchPhase.Began: if (t.fingerId == 0) { touchIndicatorOne.SetActive(true); } else if (t.fingerId == 1) { touchIndicatorTwo.SetActive(true); } if (Physics.Raycast(ray, out hit)) { if (t.fingerId == 0) { if (hit.transform.tag == "shape") { grabbedObjectOne = hit.transform.gameObject; touch = Camera.main.ScreenToWorldPoint(new Vector3(touchPosition.x, touchPosition.y, Camera.main.transform.position.y - grabbedObjectOne.transform.position.y)); offset = grabbedObjectOne.transform.position - touch; } else if (hit.collider.tag == "contact") { grabbedObjectOne = hit.transform.gameObject; touch = Camera.main.ScreenToWorldPoint(new Vector3(touchPosition.x, touchPosition.y, Camera.main.transform.position.y - grabbedObjectOne.transform.position.y)); offset = grabbedObjectOne.transform.position - touch; } } else if (t.fingerId == 1) { if (hit.transform.tag == "shape") { grabbedObjectTwo = hit.transform.gameObject; touch = Camera.main.ScreenToWorldPoint(new Vector3(touchPosition.x, touchPosition.y, Camera.main.transform.position.y - grabbedObjectTwo.transform.position.y)); offset = grabbedObjectTwo.transform.position - touch; } else if (hit.collider.tag == "contact") { grabbedObjectTwo = hit.transform.gameObject; touch = Camera.main.ScreenToWorldPoint(new Vector3(touchPosition.x, touchPosition.y, Camera.main.transform.position.y - grabbedObjectTwo.transform.position.y)); offset = grabbedObjectTwo.transform.position - touch; } } } break; case TouchPhase.Moved: if (t.fingerId == 0) { moveIndicator(touchIndicatorOne, t); if (grabbedObjectOne != null) { touch = Camera.main.ScreenToWorldPoint(new Vector3(touchPosition.x, touchPosition.y, Camera.main.transform.position.y - grabbedObjectOne.transform.position.y)); forceDirection = (touch + offset) - grabbedObjectOne.transform.position; Debug.DrawLine(grabbedObjectOne.transform.position, forceDirection, Color.red); grabbedObjectOne.GetComponent <Rigidbody> ().AddForce(forceDirection * GameManager.instance.parameters.forceMultiplier); } break; } else if (t.fingerId == 1) { moveIndicator(touchIndicatorTwo, t); if (grabbedObjectTwo != null) { touch = Camera.main.ScreenToWorldPoint(new Vector3(touchPosition.x, touchPosition.y, Camera.main.transform.position.y - grabbedObjectTwo.transform.position.y)); forceDirection = (touch + offset) - grabbedObjectTwo.transform.position; Debug.DrawLine(grabbedObjectTwo.transform.position, forceDirection, Color.green); grabbedObjectTwo.GetComponent <Rigidbody> ().AddForce(forceDirection * GameManager.instance.parameters.forceMultiplier); } break; } break; case TouchPhase.Stationary: if (t.fingerId == 0) { moveIndicator(touchIndicatorOne, t); if (grabbedObjectOne != null) { touch = Camera.main.ScreenToWorldPoint(new Vector3(touchPosition.x, touchPosition.y, Camera.main.transform.position.y - grabbedObjectOne.transform.position.y)); forceDirection = (touch + offset) - grabbedObjectOne.transform.position; Debug.DrawLine(grabbedObjectOne.transform.position, forceDirection, Color.red); grabbedObjectOne.GetComponent <Rigidbody> ().AddForce(forceDirection * GameManager.instance.parameters.forceMultiplier); } break; } else if (t.fingerId == 1) { moveIndicator(touchIndicatorTwo, t); if (grabbedObjectTwo != null) { touch = Camera.main.ScreenToWorldPoint(new Vector3(touchPosition.x, touchPosition.y, Camera.main.transform.position.y - grabbedObjectTwo.transform.position.y)); forceDirection = (touch + offset) - grabbedObjectTwo.transform.position; Debug.DrawLine(grabbedObjectTwo.transform.position, forceDirection, Color.green); grabbedObjectTwo.GetComponent <Rigidbody> ().AddForce(forceDirection * GameManager.instance.parameters.forceMultiplier); } break; } break; case TouchPhase.Ended: if (t.fingerId == 0) { touchIndicatorOne.SetActive(false); grabbedObjectOne = null; } else if (t.fingerId == 1) { touchIndicatorTwo.SetActive(false); grabbedObjectTwo = null; } break; } } } else if (Input.touchCount == 1) { foreach (Touch t in Input.touches) { Ray ray = Camera.main.ScreenPointToRay(t.position); touchPosition = t.position; switch (t.phase) { case TouchPhase.Began: if (t.fingerId == 0) { touchIndicatorOne.SetActive(true); } else if (t.fingerId == 1) { touchIndicatorTwo.SetActive(true); } if (Physics.Raycast(ray, out hit)) { if (t.fingerId == 0) { if (hit.transform.tag == "shape") { grabbedObjectOne = hit.transform.gameObject; touch = Camera.main.ScreenToWorldPoint(new Vector3(touchPosition.x, touchPosition.y, Camera.main.transform.position.y - grabbedObjectOne.transform.position.y)); offset = grabbedObjectOne.transform.position - touch; } else if (hit.collider.tag == "contact") { grabbedObjectOne = hit.transform.gameObject; touch = Camera.main.ScreenToWorldPoint(new Vector3(touchPosition.x, touchPosition.y, Camera.main.transform.position.y - grabbedObjectOne.transform.position.y)); offset = grabbedObjectOne.transform.position - touch; } } else if (t.fingerId == 1) { if (hit.transform.tag == "shape") { grabbedObjectTwo = hit.transform.gameObject; touch = Camera.main.ScreenToWorldPoint(new Vector3(touchPosition.x, touchPosition.y, Camera.main.transform.position.y - grabbedObjectTwo.transform.position.y)); offset = grabbedObjectTwo.transform.position - touch; } else if (hit.collider.tag == "contact") { grabbedObjectTwo = hit.transform.gameObject; touch = Camera.main.ScreenToWorldPoint(new Vector3(touchPosition.x, touchPosition.y, Camera.main.transform.position.y - grabbedObjectTwo.transform.position.y)); offset = grabbedObjectTwo.transform.position - touch; } } } break; case TouchPhase.Moved: if (t.fingerId == 0) { moveIndicator(touchIndicatorOne, t); if (grabbedObjectOne != null) { touch = Camera.main.ScreenToWorldPoint(new Vector3(touchPosition.x, touchPosition.y, Camera.main.transform.position.y - grabbedObjectOne.transform.position.y)); forceDirection = (touch + offset) - grabbedObjectOne.transform.position; Debug.DrawLine(grabbedObjectOne.transform.position, forceDirection, Color.red); grabbedObjectOne.GetComponent <Rigidbody> ().AddForce(forceDirection * GameManager.instance.parameters.forceMultiplier); } break; } else if (t.fingerId == 1) { moveIndicator(touchIndicatorTwo, t); if (grabbedObjectTwo != null) { touch = Camera.main.ScreenToWorldPoint(new Vector3(touchPosition.x, touchPosition.y, Camera.main.transform.position.y - grabbedObjectTwo.transform.position.y)); forceDirection = (touch + offset) - grabbedObjectTwo.transform.position; Debug.DrawLine(grabbedObjectTwo.transform.position, forceDirection, Color.green); grabbedObjectTwo.GetComponent <Rigidbody> ().AddForce(forceDirection * GameManager.instance.parameters.forceMultiplier); } break; } break; case TouchPhase.Stationary: if (t.fingerId == 0) { moveIndicator(touchIndicatorOne, t); if (grabbedObjectOne != null) { touch = Camera.main.ScreenToWorldPoint(new Vector3(touchPosition.x, touchPosition.y, Camera.main.transform.position.y - grabbedObjectOne.transform.position.y)); forceDirection = (touch + offset) - grabbedObjectOne.transform.position; Debug.DrawLine(grabbedObjectOne.transform.position, forceDirection, Color.red); grabbedObjectOne.GetComponent <Rigidbody> ().AddForce(forceDirection * GameManager.instance.parameters.forceMultiplier); } break; } else if (t.fingerId == 1) { moveIndicator(touchIndicatorTwo, t); if (grabbedObjectTwo != null) { touch = Camera.main.ScreenToWorldPoint(new Vector3(touchPosition.x, touchPosition.y, Camera.main.transform.position.y - grabbedObjectTwo.transform.position.y)); forceDirection = (touch + offset) - grabbedObjectTwo.transform.position; Debug.DrawLine(grabbedObjectTwo.transform.position, forceDirection, Color.green); grabbedObjectTwo.GetComponent <Rigidbody> ().AddForce(forceDirection * GameManager.instance.parameters.forceMultiplier); } break; } break; case TouchPhase.Ended: if (t.fingerId == 0) { touchIndicatorOne.SetActive(false); grabbedObjectOne = null; } else if (t.fingerId == 1) { touchIndicatorTwo.SetActive(false); grabbedObjectTwo = null; } break; } } } else { foreach (GameObject L in GameManager.instance.config.configuration) { L.GetComponent <Rigidbody>().velocity = new Vector3(0, 0, 0); L.GetComponent <Rigidbody>().angularVelocity = new Vector3(0, 0, 0); foreach (GameObject Magnet in L.GetComponent <LShape>().allMagnets) { Magnet.GetComponent <Rigidbody>().velocity = new Vector3(0, 0, 0); Magnet.GetComponent <Rigidbody>().angularVelocity = new Vector3(0, 0, 0); } } } } else { foreach (GameObject L in GameManager.instance.config.configuration) { L.GetComponent <Rigidbody>().velocity = new Vector3(0, 0, 0); L.GetComponent <Rigidbody>().angularVelocity = new Vector3(0, 0, 0); foreach (GameObject Magnet in L.GetComponent <LShape>().allMagnets) { Magnet.GetComponent <Rigidbody>().velocity = new Vector3(0, 0, 0); Magnet.GetComponent <Rigidbody>().angularVelocity = new Vector3(0, 0, 0); } } } }