
[ad_1]
I’m making a top-down shooter recreation and I’m attempting so as to add a muzzle flash through the use of URP mild 2D.
I’m attempting to set the goal sorting layers for the URP Light2D. I’ve seemed within the documentation and in every single place, however I can not seem to discover the code for the goal sorting layer. It appears that the goal sorting layer cannot be modified programmatically. This is an enormous downside particularly once you created the Light2D element in code.
Here is my code:
GameObject MuzzleFlash = new GameObject("MuzzleFlash");
Light2D lightComp = MuzzleFlash.AddPart<Light2D>();
lightComp.lightType = UnityEngine.Experimental.Rendering.Universal.Light2D.LightType.Point;
// Add the goal sorting layers right here
MuzzleFlash.rework.place = fromPosition; // From place is a Vector3
I’ve seemed via the Unity boards and located this:
[SerializeField] public int[] m_ApplyToSortingLayers = new int[1];
lightComp.m_ApplyToSortingLayers = new int[] {
SortingLayer.NameToID("someLayer1"),
SortingLayer.NameToID("someLayer2"),
SortingLayer.NameToID("Default"),
};
Source: Can Target Sorting Layer be set in code for Light2D?
But after I plugged that into my code, the console stated that
“‘Light2D’ doesn’t comprise a definition for ‘m_ApplyToSortingLayers’ and no accessible extension methodology ‘m_ApplyToSortingLayers’ accepting a primary argument of sort ‘Light2D’ could possibly be discovered”.
I additionally obtained this message from the console:
“Some scripts have compilation errors which can stop out of date API usages to get up to date. Obsolete API updating will proceed mechanically after these errors get fastened.”
When will there be a correct API for setting goal layers for Light2D? I’m new to Unity, so if anybody may assist me that will be nice.
[ad_2]