Skip to content

Instantly share code, notes, and snippets.

@divide-by-zero
Created April 29, 2016 16:29
Show Gist options
  • Save divide-by-zero/88e86bd99160f10af2a85babd3b9709e to your computer and use it in GitHub Desktop.
Save divide-by-zero/88e86bd99160f10af2a85babd3b9709e to your computer and use it in GitHub Desktop.
指定した一つ以上のGameObjectのlayerを一括で変更する
public class MyUtil
{
/// <summary>
/// 指定した1つ以上のGameObjectのlayerを一括で変更する
/// </summary>
/// <param name="layer">変更したいlayerId</param>
/// <param name="targetObjects">レイヤーを変更したい1つ以上のGameObject</param>
/// </summary>
public static void SetLayer(int layer,params GameObject[] targetObjects)
{
foreach (var targetObject in targetObjects)
{
targetObject.layer = layer;
}
}
/// <summary>
/// 指定した1つ以上のGameObjectのlayerを一括で変更する
/// </summary>
/// <param name="layerName">変更したいレイヤー名</param>
/// <param name="targetObjects">レイヤーを変更したい1つ以上のGameObject</param>
public static void SetLayer(string layerName,params GameObject[] targetObjects)
{
SetLayer(LayerMask.NameToLayer(layerName),targetObjects);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment