TouchMoveCamera
How do I use Touch Move Camera
Below are practical examples compiled from projects for learning and reference purposes
Featured Snippets
Line | Code | Ex.. |
---|---|---|
49 | TouchMoveCamera (); | 1 |
91 | void TouchMoveCamera(){ | 2 |
File name: CameraFollow.cs
Copy
30 void Update () {
31 if (GameplayController.instance.gameInProgress) {
32 if (isFollowing) {
33 if (GameObject.FindGameObjectWithTag ("Player Bullet") != null) {
34 MoveCameraFollow ();
35 }
36 } else {
37 if (!GameplayController.instance.player.GetChild (0).transform.GetComponent
38 MoveCameraBackToStart ();
39 AfterShotMoveAgain ();
40 allowToMove = false;
41 } else {
42 timeSinceShot = 0;
43 allowToMove = true;
44 }
45
46 }
47
48 if (Application.platform == RuntimePlatform.Android) {
49 TouchMoveCamera ();
50 } else if (Application.platform == RuntimePlatform.WindowsEditor) {
51 MoveCamera ();
52 }
53 }
54
55 }
File name: CameraFollow.cs
Copy
91 void TouchMoveCamera(){
92 if(allowToMove){
93
94 /*if(Input.touchCount > 0){
95 Touch touch = Input.GetTouch (0);
96
97 Transform cam = gameObject.transform;
98
99
100 if(touch.phase == TouchPhase.Began){
101 cam = touch.position;
102 }else if(touch.phase == TouchPhase.Moved){
103
104 }
105 }*/
106
107 if(Input.touchCount > 0){
108 Touch touch = Input.GetTouch (0);
109
110 Transform cam = gameObject.transform;
111 if (touch.position.x > 300) {
112 if(touch.phase == TouchPhase.Began || touch.phase == TouchPhase.Stationary){
113 camPos = touch.position;
114 }else if(touch.phase == TouchPhase.Moved){
115 cam.position = cam.position + (new Vector3 ((camPos.x - touch.position.x), 0, 0) * dragSpeed * Time.deltaTime);
116 float camX = cam.position.x;
117 camX = Mathf.Clamp (camX, leftBound.transform.position.x, rightBound.transform.position.x);
118 cam.position = new Vector3 (camX, cam.position.y, cam.position.z);
119 }
120 }
121
122 }
123
124 }
125 }
TouchMoveCamera 157 lượt xem
Gõ tìm kiếm nhanh...