-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbarmovement.cs
132 lines (108 loc) · 3.55 KB
/
barmovement.cs
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class barmovement : MonoBehaviour
{
// Start is called before the first frame update
public float speed = 20;
private int _modeNumber = 1; // 1:catch mode , 2:dodge mode
float middle = Screen.width / 2;
float height = Screen.height / 2;
private UIManager _uiManager;
private GameManager _gameManager;
private MoveBarUP _moveUp;
private SpawnManager _spawnManager;
private SwitchSpriteOnBall _spriteManager;
void Start()
{
transform.position = new Vector3(0f, -14f, -0.25f);
_moveUp = GameObject.Find("Floor").GetComponent<MoveBarUP>();
_uiManager = GameObject.Find("UIManager").GetComponent<UIManager>();
_gameManager = GameObject.Find("GameManager").GetComponent<GameManager>();
_spawnManager = GameObject.Find("SpawnManager").GetComponent<SpawnManager>();
nullCheck();
}
private void nullCheck()
{
if (_moveUp == null)
{
Debug.LogError("MoveUp is NULL.");
}
if (_uiManager == null)
{
Debug.LogError("UIManager is NULL.");
}
if (_gameManager == null)
{
Debug.LogError("GameManager is Null");
}
if (_spawnManager == null)
{
Debug.LogError("SpawnManager is Null");
}
}
// Update is called once per frame
void Update()
{
TouchMove();
CalculateMovement();
}
public void TouchMove()
{
if(Input.touchCount > 0)
{
Touch touch = Input.GetTouch(0);
if(touch.position.x > middle && touch.position.y < height && touch.phase == TouchPhase.Stationary)
{
MoveRight();
}
else if(touch.position.x < middle && touch.position.y < height && touch.phase == TouchPhase.Stationary)
{
MoveLeft();
}
}
}
public void MoveLeft()
{
transform.Translate(new Vector3(-1, 0, 0) * speed * Time.deltaTime);
//transform.position = new Vector3(Mathf.Clamp(transform.position.x, -14f, 14f), transform.position.y, transform.position.z);
if (transform.position.x < -14f)
{
transform.position = new Vector3(14f, transform.position.y, transform.position.z);
}
}
public void MoveRight()
{
transform.Translate(new Vector3(1, 0, 0) * speed * Time.deltaTime);
//transform.position = new Vector3(Mathf.Clamp(transform.position.x, -14f, 14f), transform.position.y, transform.position.z);
if (transform.position.x > 14f)
{
transform.position = new Vector3(-14f, transform.position.y, transform.position.z);
}
}
public void CalculateMovement()
{
if ((Input.GetKey(KeyCode.LeftArrow)))
{
MoveLeft();
}
if ((Input.GetKey(KeyCode.RightArrow)))
{
MoveRight();
}
}
public void OnTriggerEnter2D(Collider2D other)
{
if(other.tag == "collectable")
{
_uiManager.scoreUpdate(50);
Destroy(other.gameObject);
}
else if(other.tag == "evil")
{
_moveUp.moveBarUp();
_uiManager.scoreUpdate(-30);
Destroy(other.gameObject);
}
}
}