Many cameras with Camera.main.ScreenToWorldPoint trouble.

Hey, I make a 2D game where you drive car and i based riding mechanics on Camera.ScreenToWorldPoint. I want to change camera when player rides off certain zone. When i added more than 1 camera the script stopped working and my car drive off somwhere. Can somone help?

Code:
{

public Rigidbody2D rb;
public float sp;

private void Update()
{
    Vector3 mspos = Input.mousePosition;
    mspos = Camera.main.ScreenToWorldPoint(mspos);

    Vector2 dr = new Vector2(
        mspos.x - transform.position.x,
        mspos.y - transform.position.y
       );

    transform.up = dr;
    rb.AddForce(dr * sp);
}

}

Dont really understand the issue, but probably your problem is with Camera.main since thats only referencing the camera with the Camera Main tag assigned, if you want both cameras to work the same you need to pass both camera reference, not sure if that was the question.

As indicated in the documentation, Camera.main returns the first enabled camera tagged “MainCamera”. If you duplicated the Main Camera, you may have this kind of behaviour because Camera.main retrieves the incorrect camera.

In order to fix this, you can declare a public Camera and drag & drop the camera you want in the inspector. With this, you are sure the correct camera will be used (and performance will be improved, indeed, Camera.main is a costly function)

 public Rigidbody2D rb;
 public float sp;
 public Camera Camera; // Drag & drop the camera in the inspector
 private void Update()
 {
     Vector3 mspos = Input.mousePosition;
     mspos = Camera.ScreenToWorldPoint(mspos);
     Vector2 dr = new Vector2(
         mspos.x - transform.position.x,
         mspos.y - transform.position.y
        );
     transform.up = dr;
     rb.AddForce(dr * sp);
 }