void Jump() { if (input.ConnectedController) { //Jumping bool jump = Input.GetButtonDown(input.Jump); if (jump && onGround) { rigidbody.AddForce(Vector2.up * jumpForce, ForceMode2D.Impulse); } //Launching if (ball) { if (Input.GetButtonDown(input.Action)) { ball.Launch(transform.position); } } } }
void Update() { //print((int)rb.velocity.x +" " + (int)rb.velocity.y); if (CheckIfStopped()) //if ball stopped { if (ballOutOfSpawn) { //print("ball out"); //launch = true; // LimitBallSpeed(rb.velocity.x, rb.velocity.y); if (gm.activeBall == 4) { //ZeroPositions(); gm.GameOver(); } else { gm.NextBall(); ZeroPositions(); } } else { if (failedLaunch) { //print("failed launch"); canLaunch = true; } } } LimitBallSpeed(rb.velocity.x, rb.velocity.y); combinedSpeed = rb.velocity.x + rb.velocity.y; // clampedSpeed = Mathf.Clamp(combinedSpeed, 0.1f, 10.0f); if (canLaunch) { if ((CheckIfStopped() == true) && gm.activeBall < 5 && !ballOutOfSpawn) { if (Input.GetMouseButtonDown(0)) //mouse (or touch) click { Ray ray = (Camera.main.ScreenPointToRay(Input.mousePosition)); clickPos = new Vector3(ray.origin.x, ray.origin.y, 0); if (!mouseHeldDown) { //print("mouse click at " + clickPos); dot = Instantiate(aimMarker, new Vector3(clickPos.x, clickPos.y, 0), Quaternion.identity); } mouseHeldDown = true; } if (Input.GetMouseButton(0)) //mouse hold & drag, returns the current mouse position in real time for the launch aim line whateverthingymagic { Ray tempRay = (Camera.main.ScreenPointToRay(Input.mousePosition)); tempPos = new Vector3(tempRay.origin.x, tempRay.origin.y, 0); float deltaY = tempPos.y - clickPos.y; float deltaX = tempPos.x - clickPos.x; if (tempPos != clickPos) { mouseHasBeenDragged = true; //ball attempted to launch } Vector3 tempSpot = new Vector3(((transform.position.x - deltaX)), (transform.position.y - deltaY), 0); mouseHeldDown = false; } if (Input.GetMouseButtonUp(0)) //mouse release { Ray dragRay = (Camera.main.ScreenPointToRay(Input.mousePosition)); releasePos = new Vector3(dragRay.origin.x, dragRay.origin.y, 0); launcher.Launch(CalculateLaunchPower(clickPos, releasePos)); Destroy(dot); } } } }