Skip to content

Instantly share code, notes, and snippets.

@daichi-takezawa
Last active May 1, 2021 07:00
Show Gist options
  • Save daichi-takezawa/d24c1b30fb737b3ae500f4b74926d47f to your computer and use it in GitHub Desktop.
Save daichi-takezawa/d24c1b30fb737b3ae500f4b74926d47f to your computer and use it in GitHub Desktop.
Vector2 startPos,endPos;
void Flick() {
if (Input.GetKeyDown(KeyCode.Mouse0)) {
startPos = new Vector2(Input.mousePosition.x, Input.mousePosition.y);
}
if (Input.GetKey(KeyCode.Mouse0)) {
endPos = new Vector2(Input.mousePosition.x, Input.mousePosition.y);
Vector2 dt = endPos - startPos;
float radian = Mathf.Atan2(dt.x, dt.y) * Mathf.Rad2Deg;
//このままだとradianは180度と-180度表記になってしまうので下で解決する。
if (radian < 0) {
radian += 360;
}
Debug.Log(radian);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment