Search Unity

Directional Light Point In The Same Direction As Camera

Discussion in 'AR' started by Jagrth, Jan 11, 2018.

  1. Jagrth

    Jagrth

    Joined:
    Jan 11, 2018
    Posts:
    5
    Hello,

    I am trying to make it so that my directional light is pointing to wherever my camera is pointing. I have the following script.

    public class LookAtTarget : MonoBehaviour {
    public Transform target;

    // Update is called once per frame
    void Update () {
    // Rotate every frame so it keeps looking at the target
    transform.LookAt(target);
    }
    }

    I drag this script onto my Directional Light and then drag a Prefab as the target, but I cannot seem to get it working.

    Any advice is appreciated.
    Thanks.
     
  2. jimmya

    jimmya

    Joined:
    Nov 15, 2016
    Posts:
    793
    just make the directional light point in the same direction as the camera in the editor, then drag it under the camera so its a child.