Check object is inside a "simulated" camera view

I have a bit of an awkward problem that I am not sure how to go about.

I have code which determines if an object is inside a camera’s view area, which works fine for my purposes. What I want to do is to simulate this exact functionality, but for other objects which do not have an actual camera. To simulate AI that can see you, as though they were looking through their own camera. I dont want to be able to look through the AI’s camera, I just want to simulate my function for them. I would require a function which would return true if an object is inside an invisible camera view. What are my options?

For those interested, the code I use can be seen below. It only works on an active camera.

	public static bool ProjectPosition(Vector3 _pos, out float _x, out float _y) {

	Vector3 eyeSpacePos = Camera.mainCamera.WorldToScreenPoint(_pos);

	Vector3 screenSpacePos = Camera.mainCamera.ScreenToViewportPoint(eyeSpacePos);

	if (eyeSpacePos.z > 0) {
		_x = screenSpacePos.x;
		_y = screenSpacePos.y;
		return true;
	else {	
		_x = (-eyeSpacePos.x < 0) ? 0 : 1;
		_y = (-eyeSpacePos.y < 0) ? 0 : 1;
		return false;

Thanks in advance.

There are a couple ways I could think to do this. The easiest least math-intensive way is to use a temporary camera that you orient to each object, then use the code you already have. Rather than creating a separate camera for each object, just script the camera transform to each object as you need it. You would also want to set up your camera in a way that it does not affect the render output.

The second option is to do the calculations yourself using trig. This wouldn’t be too hard if you only need it to work on one plane, such as the XY floor plane. However it gets a lot more complicated if you need it to be full 3D.

If you have a lot of objects to calculate, you might consider doing this during FixedUpdate to improve performance.