wiki.sine.space | sinespace

Difference between revisions of "Scripting/SLayerMask"

From wiki.sine.space
Jump to: navigation, search
(New SLayerMask class for filtering physics hits.)
 
(Replaced content with "This page has moved to: https://docs.sine.space/v/scripting/client-scripting/static-classes/slayermask")
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
The SLayerMask class provides a wrapper around the Unity LayerMask class for filtering physics hits.
+
This page has moved to: https://docs.sine.space/v/scripting/client-scripting/static-classes/slayermask
 
+
SLayerMask will ignore any layer names that are passed into it that are unknown layers. If your layer mask isn't working as you expect it to, verify that you're using accurate layer names.
+
 
+
You can use the .Layers property to see what layers got accepted by the SLayerMask object.
+
 
+
==Members==
+
{{ScriptFunction|SLayerMask|New|(table layerNames);|Static function that creators a new layer mask from a table of layer names.|5=
+
''-- Let's create a new layer mask to filter out other avatars and vehicles:''<br>
+
local mask = LayerMask.New({"Avatars", "Vehicles"});<br>
+
local hit = Space.Physics.RaycastSingle(Space.Host.ExecutingObject.WorldPosition, Space.Host.ExecutingObject.Forward, 500.0, mask)}}
+
 
+
{{ScriptFunction|SLayerMask|New|(params string[] layerNames);|Static function that creators a new layer mask from one or more string parameters.|5=
+
''-- Let's create a new layer mask to filter out other avatars and vehicles:''<br>
+
local mask = LayerMask.New("Avatars");<br>
+
or<br>
+
local mask = LayerMask.New("Avatars", "Vehicles", "UI");<br>
+
local hit = Space.Physics.RaycastSingle(Space.Host.ExecutingObject.WorldPosition, Space.Host.ExecutingObject.Forward, 500.0, mask)}}
+
 
+
{{ScriptFunction|void|SetLayers|(table layerNames);|Function that changes an existing layer mask using a table of layer names.|5=
+
''-- Let's create a new layer mask to filter out other avatars, then overwrite it to be vehicles instead:''<br>
+
local mask = LayerMask.New({"Avatars"});<br>
+
mask.SetLayers({"Vehicles"});<br>
+
local hit = Space.Physics.RaycastSingle(Space.Host.ExecutingObject.WorldPosition, Space.Host.ExecutingObject.Forward, 500.0, mask)}}
+
 
+
{{ScriptFunction|void|SetLayers|(params string[] layerNames);|Function that changes an existing layer mask using one or more string parameters.|5=
+
''-- Let's create a new layer mask to filter out other avatars, then overwrite it to be vehicles instead:''<br>
+
local mask = LayerMask.New("Avatars");<br>
+
mask.SetLayers("Vehicles");<br>
+
local hit = Space.Physics.RaycastSingle(Space.Host.ExecutingObject.WorldPosition, Space.Host.ExecutingObject.Forward, 500.0, mask)}}
+
 
+
{{ScriptFunction|void|AddLayer|(string layerName);|Add a new layer to an existing layer mask.|5=
+
''-- Let's create a new layer mask to filter out other avatars, then add vehicles:''<br>
+
local mask = LayerMask.New("Avatars");<br>
+
mask.AddLayer("Vehicles");<br>
+
local hit = Space.Physics.RaycastSingle(Space.Host.ExecutingObject.WorldPosition, Space.Host.ExecutingObject.Forward, 500.0, mask)}}
+
 
+
{{ScriptFunction|void|RemoveLayer|(string layerName);|Remove a new layer from an existing layer mask.|5=
+
''-- Let's create a new layer mask, then remove vehicles:''<br>
+
local mask = LayerMask.New("Avatars", "Vehicles", "UI");<br>
+
mask.RemoveLayer("Vehicles");<br>
+
local hit = Space.Physics.RaycastSingle(Space.Host.ExecutingObject.WorldPosition, Space.Host.ExecutingObject.Forward, 500.0, mask)}}
+
 
+
==Properties==
+
 
+
{{ScriptFunction|string[]|Layers|{ get; set; }|The layer names represented in this layer mask|5=
+
local mask = LayerMask.New("Avatars");<br>
+
''-- Get''<br>
+
local layers = mask.Layers;<br>
+
''-- Set''<br>
+
local layers = {"Vehicles", "UI"};
+
mask.Layers = layers;
+
}}
+
 
+
 
+
{{Scripting Navbox}}
+

Latest revision as of 06:56, 19 September 2022

This page has moved to: https://docs.sine.space/v/scripting/client-scripting/static-classes/slayermask