// Update is called once per frame void Update() { if (Input.touchCount < 1) { return; } Touch touch = Input.GetTouch(0); if (touch.phase == TouchPhase.Began) { RaycastHit hit; Ray ray = camera.GetComponent <Camera>().ScreenPointToRay(touch.position); //Debug.DrawRay(ray.origin, ray.direction, Color.white, 5f); if (Physics.Raycast(ray, out hit)) { Debug.Log("Hit something"); if (hit.transform.tag != "Ammo") { return; } //Debug.Log("Hit ammo"); dragging = true; initialTouchPos = touch.position; } } else if (touch.phase == TouchPhase.Moved && dragging) { ammo.transform.localPosition = originalPos + (((camera.transform.up) * ((touch.position.y / Screen.height) - 0.5f) / 2)); Vector3 newVelocity = GetVelocity(touch); trajectoryManager.Draw(ammo.transform.position, newVelocity); } else if (touch.phase == TouchPhase.Ended && dragging) { SAmmo.Fired(); ammoRB.constraints = RigidbodyConstraints.None; Vector3 newVelocity = GetVelocity(touch); ammoRB.velocity = newVelocity; dragging = false; trajectoryManager.Disable(); uiManager.UseAmmo(ammoCount + 1); StartCoroutine(Reload(2f)); } else if (touch.phase == TouchPhase.Canceled) { dragging = false; trajectoryManager.Disable(); } else if (dragging) { Vector3 newVelocity = GetVelocity(touch); trajectoryManager.Draw(ammo.transform.position, newVelocity); } else { //Debug.Log("Not Dragging"); } }