using UnityEngine;
|
|
using System.Collections;
|
|
|
|
public class TapDetector : MonoBehaviour {
|
|
|
|
|
|
public float shortPressTime = 0.5f;
|
|
public PlayerController playerScript;
|
|
|
|
private bool isKeyDown;
|
|
private float timeDown = -1f;
|
|
private bool isLongDown = false;
|
|
|
|
|
|
// Use this for initialization
|
|
void Start () {
|
|
playerScript = GameObject.FindGameObjectWithTag("Player").GetComponent<PlayerController>();
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update () {
|
|
|
|
if (Input.anyKey) {
|
|
if (timeDown == -1f) {
|
|
timeDown = Time.time;
|
|
}else if (Time.time - timeDown >= shortPressTime) {
|
|
if (!isLongDown)
|
|
longPressDown();
|
|
longPress();
|
|
isLongDown = true;
|
|
}
|
|
}else {
|
|
if (timeDown != -1 && Time.time - timeDown < shortPressTime) {
|
|
shortPress();
|
|
}else if (timeDown != -1) {
|
|
longPressUp();
|
|
isLongDown = false;
|
|
}
|
|
timeDown = -1f;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
private void longPressDown() {
|
|
Debug.Log("longPressDown");
|
|
//playerScript.linkHook();
|
|
}
|
|
|
|
private void longPress() {
|
|
Debug.Log("holdingKey");
|
|
Debug.DrawRay(transform.position, Vector3.up * 20, Color.red);
|
|
playerScript.rotatePlayer();
|
|
|
|
|
|
}
|
|
|
|
private void longPressUp() {
|
|
Debug.Log("LongPressUp");
|
|
//playerScript.unlinkHook();
|
|
playerScript.movePlayer();
|
|
}
|
|
|
|
private void shortPress() {
|
|
Debug.Log("shorPress");
|
|
Debug.DrawRay(transform.position, Vector3.up * 20, Color.green,0.3f);
|
|
|
|
playerScript.shoot();
|
|
}
|
|
|
|
}
|