﻿using UnityEngine;
using System.Collections;

public class imuScripti : MonoBehaviour {

	public Transform playerDraggingPoint;
	public Transform player;
	public float tehoa = 3.0f;
	public float jumpingPower = 100.0f;
	public bool isDead = false;

	private bool hasJumped = false;

	// Use this for initialization
	void Start () {
	
	}

	void Update() {

		if (Input.GetMouseButtonDown(0) && !hasJumped && !isDead) {

			//Vector3 force = player.position - 
			//	Camera.main.ScreenToWorldPoint(Input.mousePosition+ new Vector3(0,0,10));

		//	Debug.Log(force);

			transform.GetComponent<Animator>().SetTrigger("jump");

			hasJumped = true;

			player.rigidbody2D.AddForce(player.up * jumpingPower);

		}

	}

	void OnCollisionEnter2D() {


		hasJumped = false;
	}
	

	// Update is called once per frame
	void FixedUpdate () {
	
		if (!isDead) {

			Vector3 force = player.position - 
			 	Camera.main.ScreenToWorldPoint(Input.mousePosition+ new Vector3(0,0,10));

			force = force.normalized;

			//Debug.Log(force);

			playerDraggingPoint.rigidbody2D.AddForce(-force*tehoa);

		}

	}
}
