// Update is called once per frame void Update() { hitNorth = Physics2D.RaycastAll(northSide.origin, northSide.direction, maxRayDistX); hitEast = Physics2D.RaycastAll(eastSide.origin, eastSide.direction, maxRayDistY); hitSouth = Physics2D.RaycastAll(southSide.origin, southSide.direction, maxRayDistX); hitWest = Physics2D.RaycastAll(westSide.origin, westSide.direction, maxRayDistY); for (int ii = 0; ii < hitNorth.Length; ii++) { RaycastHit2D hitSingleNorth = hitNorth [ii]; if (hitSingleNorth != false && hitSingleNorth.collider != null && hitSingleNorth.collider.GetComponent <MoveableObject>() != null) { if (moveObjScript = hitSingleNorth.collider.GetComponent <MoveableObject>()) { moveObjScript.DisableFlameTrail(); } //Debug.Log ("Detected collision with North side boundary"); float offset = hitSingleNorth.collider.GetComponent <CircleCollider2D> ().radius; hitSingleNorth.collider.transform.position = new Vector3(hitSingleNorth.collider.transform.position.x, -maxRayDistY / 2 + offset + 0.1f, 0); } } for (int ii = 0; ii < hitEast.Length; ii++) { RaycastHit2D hitSingleEast = hitEast [ii]; if (hitSingleEast != false && hitSingleEast.collider != null && hitSingleEast.collider.GetComponent <MoveableObject>() != null) { if (moveObjScript = hitSingleEast.collider.GetComponent <MoveableObject>()) { moveObjScript.DisableFlameTrail(); } //Debug.Log ("Detected collision with East side boundary"); float offset = hitSingleEast.collider.GetComponent <CircleCollider2D> ().radius; hitSingleEast.collider.transform.position = new Vector3(-maxRayDistX / 2 + offset + 0.1f, hitSingleEast.collider.transform.position.y, 0); } } for (int ii = 0; ii < hitSouth.Length; ii++) { RaycastHit2D hitSingleSouth = hitSouth [ii]; if (hitSingleSouth != false && hitSingleSouth.collider != null && hitSingleSouth.collider.GetComponent <MoveableObject>() != null) { if (moveObjScript = hitSingleSouth.collider.GetComponent <MoveableObject>()) { moveObjScript.DisableFlameTrail(); } //Debug.Log ("Detected collision with South side boundary"); float offset = hitSingleSouth.collider.GetComponent <CircleCollider2D> ().radius; hitSingleSouth.collider.transform.position = new Vector3(hitSingleSouth.collider.transform.position.x, maxRayDistY / 2 - offset - 0.1f, 0); } } for (int ii = 0; ii < hitWest.Length; ii++) { RaycastHit2D hitSingleWest = hitWest [ii]; if (hitSingleWest != false && hitSingleWest.collider != null && hitSingleWest.collider.GetComponent <MoveableObject>() != null) { if (moveObjScript = hitSingleWest.collider.GetComponent <MoveableObject>()) { moveObjScript.DisableFlameTrail(); } //Debug.Log ("Detected collision with West side boundary"); float offset = hitSingleWest.collider.GetComponent <CircleCollider2D> ().radius; hitSingleWest.collider.transform.position = new Vector3(maxRayDistX / 2 - offset - 0.1f, hitSingleWest.collider.transform.position.y, 0); } } }