Trigger move object only when player isn't looking at object


So I’ve gotten as far as getting a trigger that moves a target when a Player enters it.
Which is great!

public Transform OBJ;

	public Vector3 OBJTargetOffset;
	public float raiseTime = 2; 
	Vector3 OBJStart;
	Vector3 OBJTarget;
	public GameObject player;

	void Start()
		OBJStart = OBJ.position;
		OBJTarget = OBJStart + OBJTargetOffset;
	void OnTriggerEnter(Collider other)
			if(other.tag == "Player")
	IEnumerator RaiseOBJ(float time)
		float elapsedTime = 0;
		while(elapsedTime < time)
			OBJ.position = Vector3.Lerp(OBJStart, OBJTarget, elapsedTime / time);
			elapsedTime += Time.deltaTime;
			yield return null;
		OBJ.position = OBJTarget;
	void Update () {

But for a little more flexibility I’d like to find out how to have the trigger only move the target when it isn’t (or is) in the Players FOV.

Something with

Transform cameraTransform = null;
cameraTransform = GameObject.FindWithTag("MainCamera").transform;

And a ray

Vector3 rayDirection = cameraTransform.TransformDirection(Vector3.forward);
		Vector3 rayStart = cameraTransform.position + rayDirection;

Would do the job, but I just can’t seem to get it.

Thanks in advance!




Might do the trick!

Going to try and combine it with my script now.