In my game, the player is supposed to sort objects that fly toward the screen. When the player touches the flying object with their finger, the touched object is supposed to stop flying and follow the player’s finger. However, with what I currently have, the touched object follows the player’s finger but keeps flying toward the screen. Is there a way to get the selected object to stop but allow unselected objects to keep moving? All flying objects share the same script.
Edit: If this can be done by swiping them into their sorted spots, that is even better but I could not get that to work without previously selected objects copying the one that was just selected.
This is my current code:
private void FixedUpdate()
{
transform.Translate(Vector3.forward * Time.deltaTime * speed);
if (Input.touchCount > 0)
{
Ray ray = mainCamera.ScreenPointToRay(Input.GetTouch(0).position);
if (Physics.Raycast(ray, out RaycastHit raycastHit))
{
if (raycastHit.collider.GetComponent<ProjectileScript>())
{
raycastHit.collider.transform.position = new Vector3(raycastHit.point.x, raycastHit.point.y, raycastHit.collider.transform.position.z);
}
}
}
}