力度是假的,算的时间差
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ball : MonoBehaviour
{
public Transform bowl;
bool _down = false;
bool _up = false;
Vector2 _starPos,_endPos,_bowlPos;
Vector2 _line1,_line2;
float _time = 0;
// Use this for initialization
void Start ()
{
_starPos = Camera.main.WorldToScreenPoint (transform.position);
_bowlPos = Camera.main.WorldToScreenPoint (bowl.position);
_line1 = _bowlPos - _starPos;
}
// Update is called once per frame
void Update ()
{
CheckTime ();
}
public void OnPointDown()
{
Debug.Log ("按下");
_down = true;
_up = false;
_time = 0;
}
public void OnPointUp()
{
Debug.Log ("抬起 ");
_up = true;
_endPos = Input.mousePosition;
_line2 = _endPos - _starPos;
if (CheckAngle())
{
switch (CheckTime())
{
case 1:
{
Debug.Log ("move");
break;
}
case 2:
{
Debug.Log ("move Out");
break;
}
}
Debug.Log ("Time=====" + _time);
}
}
bool CheckAngle()
{
float angle = Vector2.Angle (_line1, _line2);
Debug.Log ("angle" + angle);
return angle < 30;
}
int CheckTime()
{
if (_down)
{
_time += 0.1f;
}
if (_up)
{
_down = false;
if (_time > 1 && _time < 2)
{
_time = 0;
return 1;//OK
}
else if (_time <= 1
)
{
_time = 0;
return 2;//Out
}
}
return -1;
}
}