So I wrote some code to clone all my box colliders on a building(walls etc)… but unity will not allow this after the first obstacle due to there already being one attached. Is there something I can call to override this behavior unity has?
GameObject: Screenshot - 051c5cc4036b83d66066e00633b6393e - Gyazo
Inspector: Screenshot - e63f1b836b1876d2bd7716f2af9cf6ca - Gyazo
Errors: Screenshot - 8963d82b0be45363825b1f21834a2fb7 - Gyazo
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
public class CloneBoxCollidersToNavMeshObs : MonoBehaviour
{
public void CloneAll()
{
BoxCollider[] cols = GetComponents<BoxCollider>();
Debug.Log("Found " + cols.Length );
for(int i = 0; i < cols.Length;i++)
{
NavMeshObstacle navOb = gameObject.AddComponent<NavMeshObstacle>();
if (navOb)
{
navOb.shape = NavMeshObstacleShape.Box;
navOb.size = cols*.size;*
navOb.center = cols*.center;*
navOb.carving = true;
}
}
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
[CustomEditor(typeof(CloneBoxCollidersToNavMeshObs))]
public class CloneBoxCollidersToNavMeshObsEditor : Editor
{
public override void OnInspectorGUI()
{
CloneBoxCollidersToNavMeshObs cbc = (CloneBoxCollidersToNavMeshObs)target;
if(GUILayout.Button(“Clone”))
{
cbc.CloneAll();
}
base.OnInspectorGUI();
}
}