Metron
1
Hi everyone,
consider this piece of C# code:
Camera cam = Camera.current;
if (cam == null)
{
Debug.LogError("No Camera");
}
Can anyone tell me why the log is written, although I have a rendered image on screen?
Aerozo
2
If you read the docs it says:
So I’m guessing it only works inside those 3 functions?
Metron
3
The problem is that Camera.main is not set either because my camera management doesn’t tag the currently active camera as “MainCamera”.
So what would be the right way to get the currently active camera without passing through a third object?
Aerozo
4
Well if you disable the cameras you don’t use you can always try:
Camera cam = Camera.allCameras[0];
if (cam == null)
{
Debug.LogError("No Camera");
}
That should give you the first active camera in the scene.
Metron
5
Hmmm… sounds like a solution but this might conflict with a render to target setup I might need…
I finally bit the sour apple and tagged my cameras as MainCamera upon activation.