Monday, August 22, 2022
HomeGame Developmentc# - How do I set the goal sorting layer in Unity...

c# – How do I set the goal sorting layer in Unity Light2D utilizing Common Render Pipeline (URP)


I am making a top-down shooter recreation and I am attempting so as to add a muzzle flash through the use of URP mild 2D.

I am attempting to set the goal sorting layers for the URP Light2D. I’ve seemed within the documentation and all over the place, however I can not seem to discover the code for the goal sorting layer. Evidently the goal sorting layer cannot be modified programmatically. This can be a huge downside particularly whenever you created the Light2D part in code.

Right here is my code:

    GameObject MuzzleFlash = new GameObject("MuzzleFlash");
    Light2D  lightComp = MuzzleFlash.AddComponent<Light2D>();
    lightComp.lightType = UnityEngine.Experimental.Rendering.Common.Light2D.LightType.Level;
    // Add the goal sorting layers right here
    MuzzleFlash.remodel.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"),
};

Supply: Can Goal Sorting Layer be set in code for Light2D?

However once I plugged that into my code, the console stated that
“‘Light2D’ doesn’t include a definition for ‘m_ApplyToSortingLayers’ and no accessible extension methodology ‘m_ApplyToSortingLayers’ accepting a primary argument of sort ‘Light2D’ may very well be discovered”.

I additionally acquired this message from the console:
“Some scripts have compilation errors which can stop out of date API usages to get up to date. Out of date API updating will proceed routinely 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 may be nice.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments