using UnityEngine;
using System.Collections;

public class ItemCollect: MonoBehaviour {

	public AudioClip CollectSound;
	public float HealthValue = 25;
	private PlayerState pState;
	
	// Use this for initialization
	void Start () 
	{
		GameObject gamePlayer = GameObject.FindWithTag("Player1");
		if(gamePlayer != null)
			pState = gamePlayer.GetComponent<PlayerState>();
		else 
			pState = null;
	}
	
	// Update is called once per frame
	void Update () {
		
	}
	
	void OnControllerColliderHit(ControllerColliderHit hit)
	{
		if(hit.gameObject.tag == "health")
		{
			Debug.Log(hit.gameObject.tag);	
			if(pState.Health < 100)
			{
				Destroy(hit.gameObject);
				pState.Health = Mathf.Clamp(HealthValue + pState.Health, 0,100f);
				audio.PlayOneShot(CollectSound, 0.6f);
			}
		}
	}
	
	
	
}
