Hey guys, I am trying to make a script to change the object that DOF focuses on dynamically within my script. Its working smoothly other than the fact I can’t actually reference the DepthOfField script within my script. Any suggestions?
using UnityEngine;
using System.Collections;
public class DOFCameraFocusScript : MonoBehaviour {
public float maxFocusDistance = 1000;
public GameObject camera;
public Component depthOfFieldScript;
// Update is called once per frame
void Update ()
{
if (camera == null)
{
camera = Camera.current.gameObject;
}
depthOfFieldScript = camera.GetComponent <DepthOfField> ();
RaycastHit hit;
if (Physics.Raycast(camera.transform, camera.transform.TransformDirection, out hit, maxFocusDistance))
{
DepthOfField.focalTransform = hit.collider.gameObject;
}
}
}