static public void touchCheck_Mouse() { bool[] hash = new bool[ballList.Count]; float[] sins = new float[hash.Length]; float[] coss = new float[hash.Length]; Vector3 mouseV3 = Camera.main.ScreenToWorldPoint(Input.mousePosition) - new Vector3(0, 0, Camera.main.ScreenToWorldPoint(Input.mousePosition).z); for (int ct1 = 0; ct1 < ballList.Count; ct1++) { GameObject bo = ballList[ct1]; ballPhysics bp = bo.GetComponent <ballPhysics>(); Vector3 pos = bo.transform.position; float dist = Vector3.Distance(pos, mouseV3); float dx = pos.x - mouseV3.x; float dy = pos.y - mouseV3.y; if (bp.startBall) { if (dist < bp.radius * 2) { LaunchGame(PlayerPrefs.GetInt("lastGameType") + 1); return; } } else { if (bo.transform.position.y < manager.kickZone + bp.radius) { if (Mathf.Abs(dx) <= bp.radius * (1 + (bo.GetComponent <Rigidbody2D>().gravityScale)))// && mouseV3.y < kickZone) { hash[ct1] = true; coss[ct1] = Mathf.Abs(dy / dist); sins[ct1] = dx / dist; } } } } int hitDex = -1; float lowest = 100; for (int ct1 = 0; ct1 < ballList.Count; ct1++) { if (hash[ct1]) { if (ballList[ct1].transform.position.y < lowest) { lowest = ballList[ct1].transform.position.y; hitDex = ct1; } } } if (hitDex != -1) { ballList[hitDex].GetComponent <ballPhysics>().Kick(sins[hitDex], coss[hitDex]); } }
static public void touchCheck_Touch() { List <int> newTouchIndex = new List <int>(); for (int ct1 = 0; ct1 < Input.touchCount; ct1++) { if (Input.touches[ct1].phase == TouchPhase.Began) { Vector2 tFLoorPos = Input.touches[ct1].position; tFLoorPos.y = 0; ForceUpEffect(tFLoorPos); newTouchIndex.Add(ct1); } } for (int ct1 = 0; ct1 < newTouchIndex.Count; ct1++) { bool[] hash = new bool[ballList.Count]; float[] sins = new float[hash.Length]; float[] coss = new float[hash.Length]; for (int ct2 = 0; ct2 < ballList.Count; ct2++) { hash[ct2] = false; GameObject bo = ballList[ct2]; ballPhysics bp = bo.GetComponent <ballPhysics>(); Vector3 mouseV3 = Camera.main.ScreenToWorldPoint(Input.touches[newTouchIndex[ct1]].position) - new Vector3(0, 0, Camera.main.ScreenToWorldPoint(Input.touches[newTouchIndex[ct1]].position).z); Vector3 pos = bo.transform.position; float dist = Vector3.Distance(pos, mouseV3); float dx = pos.x - mouseV3.x; float dy = pos.y - mouseV3.y; if (bp.startBall) { if (dist < bp.radius * 2) { LaunchGame(PlayerPrefs.GetInt("lastGameType") + 1); return; } } else { if (bo.transform.position.y < manager.kickZone + bp.radius) { if (Mathf.Abs(dx) <= bp.radius * (1 + (bo.GetComponent <Rigidbody2D>().gravityScale)))// && mouseV3.y < kickZone) { hash[ct2] = true; coss[ct2] = Mathf.Abs(dy / dist); sins[ct2] = dx / dist; } } } } int hitDex = -1; float lowest = 100; for (int ct2 = 0; ct2 < ballList.Count; ct2++) { if (hash[ct2]) { if (ballList[ct2].transform.position.y < lowest) { lowest = ballList[ct2].transform.position.y; hitDex = ct2; } } } if (hitDex != -1) { ballList[hitDex].GetComponent <ballPhysics>().Kick(sins[hitDex], coss[hitDex]); } } }