Hello,
how can I disable a 2D Light (Script) from the LWRP?
E.g. turning off the “Light 2D (Script)” with the “Flashlight Script”.
Thank you in advance
Hello,
how can I disable a 2D Light (Script) from the LWRP?
E.g. turning off the “Light 2D (Script)” with the “Flashlight Script”.
Thank you in advance
According to the Light2D source code, it inherits from MonoBehaviour, thus you should be able to turn off the Component with light2d.enabled = false;
Where ‘light2d’ is a variable name that points to the actual Light2D in this example.
That’s right, but my script can’t refer to the Light Script because it’s in another directory than the Flashlight Script. How can I move one to the other?
I don’t think I understand what the problem is, but here is a code snippet that hopefully helps you further. If it doesn’t help, please describe the problem in more detail.
If you add a “Light2D” field to the Flashlight Component and then assign the Light2D in the Inspector, you can manipulate it inside the Flashlight code as shown below.
using UnityEngine;
class Flashlight : MonoBehaviour
{
[SerializeField]
UnityEngine.Experimental.Rendering.LWRP.Light2D m_Light2D = null;
void Update()
{
m_Light2D.enable = false;
}
}
If I have understood you correctly, you are unsure how to access data from one script in another? If that is the case, I recommend following the tutorials in the learn section.
You can get a reference by using a public reference and slotting it in the inspector, such as what @Peter77 has shown above.
Alternatively you can make the script a static singleton (not recommended, and in general will create spaghetti code) and access it anywhere. Both of these are touched on in the basic tutorials. Good luck!
That worked, thank you