- Home /
Modify 2D Point Light Distance in runtime?
My game has a camera stack with mixed 3D and 2D rendering. I'm moving the 2D light's x position to match the position of the 3D skybox light. I'd like to do the same with the z position of the 2D light using the point light's Distance variable, but it's read only and I can't manipulate it in runtime via script.
//get 3D skybox sun angle
float sunRotation = cameraRotation.localEulerAngles.y;
sunRotation = (sunRotation > 180) ? sunRotation - 360 : sunRotation;
//move 2D light's x pos in relation
transform.position = new Vector3(sunRotation / 18f, transform.position.y, transform.position.z);
light2D.pointLightDistance = TODO;
Any idea why it would be read only and if there's a work around to changing that? You might say just move the 2D light with it's z transform, but it doesn't work like that because it's a 2D light.
Thanks!
Answer by spaceowlpro · Apr 21, 2021 at 02:00 PM
A hack fix for this is to utilize a Playable Director timeline that controls the pointLightDistance parameter as an Animation Track and then just move the timeline's playhead in script, but actually now that I tried it it doesn't want to update the distance in runtime even with this method... strange.
My new fix is that I made 2 2D Point Lights with different distances to simulate what I was wanting and then I just mix between the two gradually as the 3D light rotates. It's not as pretty looking but it works for now!
Your answer
![](https://koobas.hobune.stream/wayback/20220613032610im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
2D Light question 1 Answer
Unity 2D Lighting Effect 1 Answer
Flickering circle of light around character 0 Answers
2d Lighting - Weird light triangles 0 Answers