My script isnt adding the collider could because of layers i have no idea!! i think i should use tags instead of layers but how would i do that ???
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class PreviewObject : MonoBehaviour
{
public bool foundation;
public List<Collider> col = new List<Collider>();
public Material green;
public Material red;
public bool isBuildable;
void OnTrggerEnter(Collider other)
{
if (other.gameObject.layer == 9 && foundation )
col.Add (other);
}
void Update()
{
changecolor();
}
void OnTriggerExit(Collider other)
{
if (other.gameObject.layer == 9 && foundation)
col.Remove (other);
}
public void changecolor()
{
if (col.Count == 0)
isBuildable = true;
else
isBuildable = false;
if (isBuildable)
foreach (Transform child in this.transform)
{
child.GetComponent<Renderer>().material = green;
}
else
{
foreach (Transform child in this.transform)
{
child.GetComponent<Renderer>().material = red;
}
}
}
}