void Update() { if (Input.touchCount > 0 && !isTouching || isDebug && Input.GetKeyDown(KeyCode.Space)) { isTouching = true; Ray touchRay = GenerateTouchray(); RaycastHit hit; //Debug.DrawRay(touchRay.origin, touchRay.direction * 100f, Color.red); if (Physics.Raycast(touchRay.origin, touchRay.direction, out hit)) { if (hit.transform.GetComponent <IsDraggable>()) { currentObject = hit.transform.gameObject; hitPoint = hit.point; hit.collider.enabled = false; mZCoord = Camera.main.WorldToScreenPoint(currentObject.transform.position).z; mOffset = currentObject.transform.position - GetTouchAsWorldPoint(); } else { if (player.isGrounded()) { player.DoJump(); } } } } if (Input.touchCount > 0 && currentObject) { if (currentObject.GetComponent <Rigidbody>() == null) { currentObject.AddComponent <Rigidbody>(); } currentObject.GetComponent <Rigidbody>().mass = CustomMass; currentObject.GetComponent <Rigidbody>().isKinematic = false; currentObject.transform.position = GetTouchAsWorldPoint() + mOffset; } if (Input.touchCount == 0 || isDebug && Input.GetKeyUp(KeyCode.Space)) { isTouching = false; if (currentObject) { currentObject.GetComponent <IEvent>().DisableEvent(); releasePoint = currentObject.transform.position; currentObject.GetComponent <Rigidbody>().AddForce((releasePoint - hitPoint) * ForceToAdd); currentObject = null; } } scoreText.text = currentscore.ToString(); highscoreText.text = highscore.ToString(); if (isDebug) { fpsCounter.text = "FPS " + ((int)(1f / Time.unscaledDeltaTime)).ToString() + " || " + player.isGrounded() + " || " + tileMoveSpeed.ToString(); } }