Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Screen position out of view frustum" in Unity 3D

I'm trying to dynamically set the position and size of my camera in my scene,If I execute the below code the error occurs.It works fine if I set the properties in my scene,so the error is in my code

Error : Screen position out of view frustum (screen pos 959.000000, 454.000000) (Camera rect 0 0 960 907) UnityEngine.SendMouseEvents:DoSendMouseEvents(Int32)

using UnityEngine;
public class CameraInt : MonoBehaviour
{
    public Camera cam1;
    private int row, col;
    private float size;
    void Start()
    {
        MazeLoader ml = gameObject.AddComponent<MazeLoader>();
        row = ml.mazeRows;
        col = ml.mazeColumns;
        size = ml.size;
        float r = row * size / 2;
        cam1.transform.Translate(new Vector3(r, 0,col*size/2),Space.World);
        cam1.orthographicSize = r;
    }
}
  • Camera View : Orthographic
  • Unity version : 2019.3.13f1
like image 956
Maghil vannan Avatar asked Oct 26 '25 08:10

Maghil vannan


1 Answers

The error occurs if camera size is set to 0

this line was the cause of error : cam1.orthographicSize = r;

like image 129
Maghil vannan Avatar answered Oct 28 '25 23:10

Maghil vannan