I have a script to capture the height, width and distance from the camera.
This script is associated with the Main Camera and works normally.
using UnityEngine;
public class GerenciarCamera : MonoBehaviour
{
public Camera camera1;
private static float minX;
private static float minY;
private static float maxX;
private static float maxY;
private float distanciaZ;
void Start()
{
distanciaZ = transform.position.z - camera1.transform.position.z;
minX = camera1.ScreenToWorldPoint(new Vector3(0, 0, distanciaZ)).x;
maxX = camera1.ScreenToWorldPoint(new Vector3(Screen.width, 0, distanciaZ)).x;
minY = camera1.ScreenToWorldPoint(new Vector3(0, 0, distanciaZ)).y;
maxY = camera1.ScreenToWorldPoint(new Vector3(0, Screen.height, distanciaZ)).y;
}
public static float MinX()
{
return minX;
}
public static float MinY()
{
return minY;
}
public static float MaxX()
{
return maxX;
}
public static float MaxY()
{
return maxY;
}
}
By reopen the project in Unity, it seems that the script stops working. To make it work, I remove it from the Main Camera, and readd again. This way works.
What could be wrong? Bug?
Thank’s