﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class TilePlaceholderBehaviour : MonoBehaviour {

    private void OnTriggerStay(Collider other)
    {
        if (other.gameObject.CompareTag("Placable"))
        {
            Renderer[] rendererComponents = GetComponentsInChildren<Renderer>(true);
            Collider[] colliderComponents = GetComponentsInChildren<Collider>(true);

            // Disable rendering:
            foreach (Renderer component in rendererComponents)
            {
                component.enabled = false;
            }

            // Disable colliders:
            foreach (Collider component in colliderComponents)
            {
                if (!component.isTrigger)
                {
                    component.enabled = false;
                }
            }
        }
    }

    private void OnTriggerExit(Collider other)
    {
        if (other.gameObject.CompareTag("Placable"))
        {
            Renderer[] rendererComponents = GetComponentsInChildren<Renderer>(true);
            Collider[] colliderComponents = GetComponentsInChildren<Collider>(true);

            // Enable rendering:
            foreach (Renderer component in rendererComponents)
            {
                component.enabled = true;
            }

            // Enable colliders:
            foreach (Collider component in colliderComponents)
            {
                if (!component.isTrigger)
                {
                    component.enabled = true;
                }
            }
        }
    }
}
