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

public class PlayerAttractRadius : MonoBehaviour {

	//public GameObject objToAttract;
	//private GameObject[] objsToAttract;

	public float strenghOfAttraction = 5.0f;

	// Use this for initialization
	void Start () {
		
	}
	
	// Update is called once per frame
	void FixedUpdate () {

		GameObject[] objsToAttract = GameObject.FindGameObjectsWithTag ("garbage_attract");

		foreach (GameObject garbageAttract in objsToAttract) {
			
			Vector3 direction = garbageAttract.transform.position - transform.position;
			garbageAttract.GetComponent<Rigidbody> ().AddForce (strenghOfAttraction * direction);

		}
			
	}

	void OnTriggerEnter (Collider toucher) {
		if (toucher.tag == "garbage") {
			toucher.tag = "garbage_attract";


		}
	}

	void OnTriggerExit (Collider toucher) {
		if (toucher.tag == "garbage_attract") {
				toucher.tag = "garbage";
			}
	}
		
}
