How can i set the sun transform value on the SunShafts script?

The Sun Shafts script is only available to Unity Pro users and is not directly attainable through code, so I figured I would use GetComponent and reflection to set the sunTransform field via code. (Since setting it manually in every scene is painful to maintain).

This is the code I was hoping would work, but it did not:

Component sunShafts = GetComponent("SunShafts");
sunShafts.GetType().GetField("sunTransform").SetValue(sunShafts, SunShaftsCaster.Instance.transform);

I had to fully convert the scripts to C#, to get it to work with the rest of my assets. (I use only C# scripts.) After you convert all of the scripts, it’s very easy to use and change settings/assign objects at runtime. Just make sure you convert all of the dependency scripts, that are used by/for the Sun Shafts. It took me a while to do it, but I am sure happy with the outcome.

You do not have to change the shaders, just the scripts that use them. Ensure that you set the shaders, after converting, in the inspect also.

After it’s all complete, you can adjust the values like so:

Camera.mainCamera.GetComponent<SunShafts>().sunTransform = sunLocator.transform;
Camera.mainCamera.GetComponent<SunShafts>().enabled = true;