Spotlight Direction

I am trying to set the direction of a spotlight created from script. I have a normal which represent the direction but spotlights do not take normals as direction. How can I convert normals to degrees to then use Quaternion.Euleur(Vector3 v)

Better yet, can I directly convert the normals to represent the direction of the spotlight?

spotlight is just a light

light is just a component, much like any of your monobehaviors

components sit on gameObjects

gameObjects have Transform, accessible as this.transform

You can convert any vector for example new Vector3(0, 0, 1) which in this case is a forward vector, by using Quaternion.LookRotation(myForwardsVector, myUpDirection) which returns quaternion

you can already assign quaternion to transform.rotation, but if you want degrees you can always get them like: myQuaternion.eulerAngles;


but wouldn’t transform.LookRotation() be easier for you?

I took your advice and I am using this:

lightGameObject.transform.localRotation = Quaternion.LookRotation(normal,lightGameObject.transform.up);

Is there any case when this will fail? Cannot comment due to lack of permissions.