MoveCamera
How do I use Move Camera
Below are practical examples compiled from projects for learning and reference purposes
Featured Snippets
Line | Code | Ex.. |
---|---|---|
34 | MoveCameraFollow (); | 1 |
57 | void MoveCameraFollow(){ | 2 |
63 | void MoveCameraBackToStart(){ | 3 |
76 | void MoveCamera(){ | 4 |
91 | void TouchMoveCamera(){ | 5 |
16 | MoveCamera(); | 6 |
21 | void MoveCamera() { | 7 |
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
57 void MoveCameraFollow(){
58 if(target != null){
59 transform.position = Vector3.Lerp (new Vector3 (transform.position.x, 0, -10f), new Vector3 (Mathf.Clamp (target.transform.position.x, leftBound.position.x, rightBound.position.x), 0, transform.position.z), Time.deltaTime * 10);
60 }
61 }
File name: CameraFollow.cs
Copy
63 void MoveCameraBackToStart(){
64 transform.position = Vector3.MoveTowards (transform.position, startPosition, Time.deltaTime * 5f);
65 }
File name: CameraFollow.cs
Copy
76 void MoveCamera(){
77 arrowX = Input.GetAxis ("Horizontal");
78
79 Transform cam = gameObject.transform;
80
81 if (allowToMove) {
82 if (arrowX != 0) {
83 cam.position = cam.position + (new Vector3 (arrowX, 0, 0) * speed * Time.deltaTime);
84 float camX = cam.position.x;
85 camX = Mathf.Clamp (camX, leftBound.transform.position.x, rightBound.transform.position.x);
86 cam.position = new Vector3 (camX, cam.position.y, cam.position.z);
87 }
88 }
89 }
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 }
File name: CameraMove.cs
Copy
13 void Update () {
14 if (PlayerScript.instance != null) {
15 if (PlayerScript.instance.isAlive) {
16 MoveCamera();
17 }
18 }
19 }
File name: CameraMove.cs
Copy
21 void MoveCamera() {
22 Vector3 temp = transform.position;
23 temp.x = PlayerScript.instance.GetPositionX() + offSetX;
24 transform.position = temp;
25 }
MoveCamera 162 lượt xem
Gõ tìm kiếm nhanh...