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

[RequireComponent(typeof(AttractRepelObject))]
public class MagnetCube : MonoBehaviour {

    public Material magnet_off;
    public Material magnet_on;

    public float strength;
    public string[] tags;

    private Collider[] trigger;
    private AttractRepelObject magnet;
    private Renderer render;

	// Use this for initialization
	void Start () {
        trigger = GetComponents<Collider>();
        render = GetComponent<Renderer>();
        magnet = GetComponent<AttractRepelObject>();
	}
	
	// Update is called once per frame
	void Update () {
		
	}

    void OnTriggerEnter(Collider other){
        for (int i = 0; i < tags.Length; i++)
        {
            if (other.CompareTag(tags[i]))
            {
                render.material = magnet_on;
                magnet.strength = strength;
            }
        }
    }

    private void OnTriggerExit(Collider other){
        for (int i = 0; i < tags.Length; i++)
        {
            if (other.CompareTag(tags[i]))
            {
                render.material = magnet_off;
                magnet.strength = 0;
            }
        }
    }
}
