void Update() { if (Input.touchCount < 1) { return; } Touch touch = Input.GetTouch(0); //Visial Debugging Vector2 touchPos = Camera.main.ScreenToWorldPoint(touch.position); Color circleColor = Color.white; // Cache the touch data (for GUI). _touchData = new TouchData(touch); if (touch.phase == TouchPhase.Moved) { if (TouchSpeedIsSignificant(touch)) { //Swipe gesture detected if (!_swipeTrail.activeInHierarchy) { _swipeTrail.SetActive(true); } _swipeTrail.transform.position = touchPos; circleColor = Color.red; } } GLDebug.DrawCircle(touchPos, .3f, circleColor, 2f); }
void Update() { if (Input.GetKeyDown("r")) { Application.LoadLevel(Application.loadedLevel); } // MOUSE : Power Adjust if (Input.GetAxis("Mouse ScrollWheel") != 0) { dist += Input.GetAxis("Mouse ScrollWheel"); //if (dist>minDist) dist=minDist; dist = Mathf.Clamp(dist, maxDist, minDist); //Debug.Log("dist:"+dist); slider.value = -maxDist - minDist - (dist + -maxDist - minDist); //slider.image.color = Color.Lerp(Color.green,Color.red,slider.normalizedValue); //Debug.Log(slider.normalizedValue); } // MOUSE: Get mouse position Vector3 mPos = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, 10)); // rotate stick around ball if (follow) { // TODO: add force distance here? Vector3 temp = (stick.position - ball.position).normalized; stick.rotation = Quaternion.LookRotation(Vector3.forward, mPos - ball.position); stick.position = ball.position; stick.localPosition += stick.up * dist; // raycast from ball to forward hit = Physics2D.CircleCast(ball.position, ballRadius, stick.up, 99, layerMaskBallsAndWalls); // we hit other balls if (hit.collider != null) { // from stick/ball to target GLDebug.DrawLine(stick.position, hit.centroid, Color.white, 0, false); // circle preview gizmo GLDebug.DrawCircle(hit.centroid, ballRadius, Color.yellow, 0, false); // get reflection direction for whiteball Vector3 reflectDir = Vector3.Reflect((new Vector3(hit.centroid.x, hit.centroid.y, 0) - stick.position).normalized, hit.normal); GLDebug.DrawRay(hit.centroid, reflectDir, Color.yellow, 0, false); // target ball estimated direction if (hit.collider.CompareTag("Ball")) { Vector3 targetDir = (hit.transform.position - new Vector3(hit.centroid.x, hit.centroid.y, 0)).normalized * 10; GLDebug.DrawRay(hit.centroid, targetDir, Color.red, 0, false); } } else { // no hit on balls // then raycast to walls instead hit = Physics2D.CircleCast(stick.position, ballRadius, stick.up, 99, layerMaskWalls); if (hit.collider != null) { GLDebug.DrawLine(stick.position, hit.centroid, Color.red, 0, false); Vector3 reflectDir2 = Vector3.Reflect((new Vector3(hit.centroid.x, hit.centroid.y, 0) - stick.position).normalized, hit.normal); GLDebug.DrawRay(hit.centroid, reflectDir2, Color.red, 0, false); } else { } } } // MOUSE: Shoot if (follow && Input.GetMouseButtonUp(0)) // && hit.collider != null) { stick.GetComponent <AudioSource>().volume = Mathf.Lerp(0, 1, ReMap(dist, maxDist, minDist, 1, 0)); stick.GetComponent <AudioSource>().Play(); Vector3 forceDir = (ball.position - stick.position).normalized * -(dist - minDist - 0.02f) * forceMultiplier; ball.GetComponent <Rigidbody2D>().AddForce(forceDir, ForceMode2D.Impulse); follow = false; Invoke("HideShowStick", 0.2f); } // start following if (!follow) { if (ball.GetComponent <Rigidbody2D>().velocity.sqrMagnitude < 0.015f) { follow = true; selectionFx.GetComponent <Fader>().StartFade(); Invoke("HideShowStick", 0.2f); } } } // update()