TouchCannonMovement
How do I use Touch Cannon Movement
Below are practical examples compiled from projects for learning and reference purposes
Featured Snippets
Line | Code | Ex.. |
---|---|---|
55 | TouchCannonMovement (); | 1 |
172 | void TouchCannonMovement(){ | 2 |
File name: Cannon.cs
Copy
43 void Update () {
44 if (GameplayController.instance.gameInProgress) {
45 if (readyToShoot) {
46 if(Application.platform == RuntimePlatform.Android){
47 TouchCannonShoot ();
48 }else if(Application.platform == RuntimePlatform.WindowsEditor){
49 CannonShoot ();
50 }
51
52 }
53
54 if(Application.platform == RuntimePlatform.Android){
55 TouchCannonMovement ();
56 }else if(Application.platform == RuntimePlatform.WindowsEditor){
57 CannonMovement ();
58 }
59
60 }
61 }
File name: Cannon.cs
Copy
172 void TouchCannonMovement(){
173 if(Input.touchCount > 0){
174 Touch touch = Input.GetTouch (0);
175
176 if (touch.position.x < 300 && !isCharging && touch.position.y > 160) {
177
178 if (touch.phase == TouchPhase.Moved) {
179 Vector2 touchDeltaPosition = touch.deltaPosition;
180 direction = touchDeltaPosition.normalized;
181
182 if (direction.y > 0 && touchDeltaPosition.x > -10 && touchDeltaPosition.x < 10) {
183 currentRotation.z += 50f * Time.deltaTime;
184 } else if (direction.y < 0 && touchDeltaPosition.x > -10 && touchDeltaPosition.x < 10) {
185 currentRotation.z -= 50f * Time.deltaTime;
186 }
187
188 }
189 }
190 }
191
192 currentRotation.z = Mathf.Clamp(currentRotation.z, minRot, maxRot);
193
194 transform.rotation = Quaternion.Euler (currentRotation);
195
196 }
TouchCannonMovement 121 lượt xem
Gõ tìm kiếm nhanh...