- Home /
Question by
Jus_de_Pom · Apr 12, 2021 at 09:00 PM ·
layerslayermaskarraylist
How to take only objects with a certain layer ? c#
Hello, I want to add a component on objects that have certains layer based on an array of of LayerMasks. Here is my code
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GeneralSettings : MonoBehaviour {
public float gravityForce = 9.81f;
public AppliedGravityObjects[] appliedGravityObjects;
private void Start()
{
GameObject[] objectsWithGravity = FindObjectsOfType<GameObject>();
for (int i = 0; i < appliedGravityObjects.Length; i++)
{
for (int e = 0; e < objectsWithGravity.Length; e++)
{
if (appliedGravityObjects[i].objectLayer.value == objectsWithGravity[e].layer)
{
Debug.Log(objectsWithGravity[e].name + " " + objectsWithGravity[e].layer);
}
}
}
}
}
[System.Serializable] public class AppliedGravityObjects {
public string name;
public LayerMask objectLayer;
}
Comment
Your answer
Follow this Question
Related Questions
How to get all layers included in a LayerMask? 4 Answers
Flare showing in cameras that should not show it 1 Answer
Know if layer is in use 1 Answer
Enable disable layerMask 0 Answers