Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


ToString()

Given a layer mask, returns a comma seperated list of the names of the layers in this mask. The names are as defined in either a Builtin or a User Layer in the Tags and Layers manager.
Read time 1 minuteLast updated 4 days ago

Definition

  • Type: Method
  • Namespace: UnityEngine
  • Assembly: UnityEngine.CoreModule
public override string ToString()

Returns

Type

Description

string

Remarks

using UnityEngine;public class Example : MonoBehaviour{ void Start() { // Converts an int to a layer mask and prints all the layer names. // As the value is 3, it will print "Default" and "TransparentFX". // 2^0 + 2^1 = 1 + 2 = 3 int number = 3; LayerMask layerMask; // ✅ This line is the key to this example: // Implicitly converts the integer 'number' into a LayerMask. // This uses LayerMask.LayerMask implicitly. layerMask = number; // "Default, TransparentFX" Debug.Log(layerMask.ToString()); }}
Returns either the Layer name, or the bit index if no name is set. If called off of the Main Thread, the enabled Layer indices in the mask are returned instead of each layer name as layer name retrieval must occur on the Main Thread.