- Home /
Collider Array showing up empty,No Colliders showing up in my array
Trying to create a system for a player to switch between foreground, background ect. The problem I have is getting the layers that the player isn't currently on to ignore collision. Here's my code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BackGround : MonoBehaviour
{
Collider[] colliderList;
// Start is called before the first frame update
void Start()
{
colliderList = GetComponentsInChildren<Collider>();
Debug.Log(colliderList.Length);
}
// Update is called once per frame
void Update()
{
if (GameObject.Find("Player").layer != gameObject.layer){
for (int i = 0; i < colliderList.Length; i++) {
Debug.Log("Beta");
Physics.IgnoreCollision(GameObject.Find("Player").GetComponent<Collider>(), colliderList[i]);
}
}
}
}
The problem is the array shows up as having no elements in it, despite there being 2 colliders for it to detect. Does anyone have a better way to do this or a solution?
Thanks.
Comment
Your answer
Follow this Question
Related Questions
How to use collision.name in custom function 1 Answer
Help with bombs destroying colliders in different position from gameobject 0 Answers
Distribute terrain in zones 3 Answers
How can I detect a collision between two clones and delete them both? 1 Answer
[RESOLVED] Pressing the "Z" key to make him go through certain terrain objects? 1 Answer