using UnityEngine;
using System.Collections;

public class PlayerControl : MonoBehaviour
{
	public float speed = 3.5F;
	public GUIText cntText;
	public GUIText resultText;
	private int cnt;
	private bool _isEnd = false;

	void Start()
	{
		cnt = 0;
		SetText();
	}
	
	// Update is called once per frame
	void FixedUpdate ()
	{
		if(!_isEnd)
		{
			movePlayer();
		}
	}

	void movePlayer()
	{
		float h = speed * Input.GetAxis("Horizontal");
        float v = speed * Input.GetAxis("Vertical");
        
        Vector3 pos = new Vector3(h, 0, v);
        GetComponent<Rigidbody>().AddForce(pos * Time.deltaTime * 100);
	}
	
	void OnTriggerEnter(Collider other)
	{
		//Destroy(other.gameObject);
		if(other.gameObject.tag == "PickUp")
		{
            GetComponent<AudioSource>().Play();
            other.gameObject.SetActive(false);
			cnt += 1;
			SetText();
		}
	}
	
	void SetText()
	{
		cntText.text = cnt.ToString() + " Pt";
		
		if(cnt > 2)
		{
			resultText.text = "MISSON\nCOMPLETE";
			_isEnd = true;
		}
	}
}