No current camera?

A Canvis, add the script to the Canvas.

Update() call the below script.

void MouseClick()
    {
        if (Input.GetMouseButtonDown(0))
        {
            Ray ray = Camera.current.ScreenPointToRay(Input.mousePosition);
            print("aa");

            if (Physics.Raycast(ray, out hit))
            {}
}
}

The problem is that print is not executed, and the error is " reference to null " at the screenpointtoray.

If i change “current” to “main”, it works fine.

I only have one main camera in the scene, isnt current camera the same as main camera?

Use Camera.main.

Just like it tells you to.

1 Like

Why ppl always think the document is enough and link them as answer? :frowning:

If document is so powerful, every student in colleagues should score 100 as long as they read textbook.

I have another project that have 3 camera, and the Camera.current work fine. That’s why i want to find out what happen.

1 Like

Are you sure you’re using the Camera.current exactly the same way in the other project? Since Camera.current is the “camera we are currently rendering with, for low-level render control only, I don’t think you should use it to handle input. Use Camera.main or assign your script a reference to the correct camera.

Actually the script is copied from the “ok” 3 cameras project, and then i find it doesnt work, so i change it to “main” in the new project.

1 Like