My sprite disappears from the camera view after some time moving

I set up a sprite to be moved by touch input, and it simply disappears after some time from the camera view, but not the scene. Here is the moving script:

using UnityEngine;
using System.Collections;

public class Drag2 : MonoBehaviour 
	public GameObject cube;
	// Update is called once per frame
	public float speed = 0.1F;
	void Update() 
		if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Moved) 
			//Vector2 touchDeltaPosition = Input.GetTouch(0).deltaPosition;
			//cube.transform.Translate(touchDeltaPosition.x * speed, touchDeltaPosition.y * speed, 0);

			Touch touch = Input.GetTouch(0);
			Vector3 touchPosition = Camera.main.ScreenToWorldPoint(new Vector3(touch.position.x, touch.position.y, 0));                
			cube.transform.position = Vector3.Lerp(cube.transform.position, touchPosition, Time.deltaTime);

And here are some screenshots of before and after the sprite is gone:

Well, If I understood your question the problem is that the object is not showing in the game screen despite it being inside the area according to the scene view. If this is the problem then I’m not even gonna read the script cause the movement isn’t the problem. So it might be:

  1. You didn’t set up the layers correctly.
  2. The camera is not set to a Z value inferior to the rest of the stuff, e.g. all stuff should be at Z = 0 and camera at Z = -10
    I don’t think it is 1) cause You dont seem to have any background to be overlaying. But if it were you would have to go tto the sprite renderer in each object and change sorting layer in each one being the moving object over the background

If it is 2) you just have to change the Z values.
It may also be something to do with your camera detinitions. prespective vs /orthographic try changing settings there if the rest doesn’t work. Right now I don’t remember any other cause to your problem

Thanks, @Miguel_cs, I solved the issue by messing around with the clipping planes on the camera. Must be some annoying little bug!

@MIguel_cs Your answer was fantastic. I have been having the same problem, and it turned out all I had to, as you said, was to move the sprites from Layer 0 to Layer 1.

Thank you very much.

When you use Camera.main.ScreenToWorldPoint() the returning Vector3 will have the Z value that the main Camera has.

Therefore, the first you want to do with the returning Vector3 is set the Z to 0.

I had some headache before figuring this out. Hope it helps!

I am having this same problem, however changing the layer of my sprite does not help. I have also changed the Z axis to be in front of everything else, my camera is also set to Z -10. Please help! Thanks!