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

public class CollectorS : MonoBehaviour {

	public BallS ball;
	public CatcherS catcher;
	public StateHandlerS stateHandler;
	public string collectColor;

	void OnTriggerEnter2D(Collider2D col) {
		checkCollect (col);
	}

	void OnTriggerStay2D(Collider2D col) {
		checkCollect (col);
	}

	private void checkCollect(Collider2D col) {
		if (col.gameObject.tag == "CATCHER" && catcher.catched
			&& col.gameObject.GetComponent<CatcherS>().catchedColor == collectColor) {
			ball.transform.position = BallS.startPosition;
			ball.rb2d.velocity = Vector2.zero;
			ball.rb2d.angularVelocity = 0;
			ball.rb2d.gravityScale = 0;
			ball.transform.parent = null;
			ball.rb2d.isKinematic = false;
			ball.setRandomColor ();
			ball.thrown = false;
			catcher.catched = false;
			stateHandler.scoreCount++;
		}
	}
}
