-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTapController.cs
More file actions
executable file
·50 lines (43 loc) · 1.11 KB
/
TapController.cs
File metadata and controls
executable file
·50 lines (43 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
using UnityEngine;
using UnityEngine.EventSystems;
using System.Collections;
public class TapController : MonoBehaviour {
public Rigidbody rigidBody;
public Vector2 jumpForce = new Vector2(0, 4f);
void Update () {
if (this.UserDidTapOnPhone () && !this.UserTappedOnMenu() || this.UserDidEditorTap()) {
this.AddForceToGameObject ();
}
}
private void AddForceToGameObject() {
this.rigidBody.velocity = Vector2.zero;
this.rigidBody.AddForce(this.jumpForce, ForceMode.Impulse);
}
private bool UserDidTapOnPhone() {
var didTap = false;
foreach(Touch touch in Input.touches) {
if(touch.phase == TouchPhase.Began) {
didTap = true;
}
}
return didTap;
}
private bool UserTappedOnMenu() {
bool didTapMenu = false;
if(Input.touchCount > 0) {
int pointerID = Input.touches[0].fingerId;
if (EventSystem.current.IsPointerOverGameObject(pointerID))
{
didTapMenu = true;
}
}
return didTapMenu;
}
private bool UserDidEditorTap() {
var didEditorTap = false;
if(Application.isEditor && Input.GetKeyUp(KeyCode.Space)) {
didEditorTap = true;
}
return didEditorTap;
}
}