Unity - Light Flicker Script not running/working on Play

45 Views Asked by At

I am very new to both C# and Unity, so I have been following some tutorials to create a Wall Torch (GameObject) that has a child 2D Spot Light which flickers using the following script I found on Github. https://gist.github.com/sinbad/4a9ded6b00cf6063c36a4837b15df969 According to Visual Studio, the script has no errors.

However, upon hitting Play to start the script, nothing happens. There are no errors or messages in the Console.

Example

I have attached the script as a component to the 2D light, and made sure the class and script name are identical.

I have tried restarting the project and creating a new one, as well as deleting and recreating the script. The Unity project is 2D with URP.

I really appreciate any help.

1

There are 1 best solutions below

1
Cyclone6664 On BEST ANSWER

I haven´t tested this, but I think the problem is that the script tries to get a Light component from your GameObject, but you have a Light2D component. Try replacing the public new Light light; line in the script with public Light2D light;, and on line 45 change Light to Light2D, and it should work;