Need help in my Camera Control script

I want to create a RTS camera on mobile devices, but now i have problem with my mouse press extension.
Here’s code:

using UnityEngine;

public class CameraControler : MonoBehaviour
{
    Vector3 touchStart;

    void Start()
    {

    }
    void Update()
    {

        if (Input.GetMouseButtonDown (0))
        {
            touchStart = Camera.main.ScreenToWorldPoint(Input.mousePosition);   
        }

        if (Input.GetMouseButton(0))
        {
            Vector3 direction = touchStart - Camera.main.ScreenToWorldPoint(Input.mousePosition);
            Camera.main.transform.position += direction;
        }
    }
}

You should state what the problem is.

The problem is that camera doesn’t move

I’d recommend adding some Debug.Log statements to your code, so you can make sure the code is being called.

Looking at this again, though, I’m not sure your logic makes sense. It seems like this code would keep adding to the camera’s position even if you weren’t moving the mouse. Two approaches would be to set the position to direction, not add direction to it. Or, keep track of the last position (instead of touchStart) from the last frame, and do the delta based on that.

You’re also translating the XY 2D position of the mouse to 3D position. Are you sure that’s what you want? I’d think you might want to change the camera’s XZ values based on the mouse movement’s XY value.