Game đua xe 3D
29.385 lượt xem;
1 using UnityEngine;
2 using System.Collections;
3
4 [RequireComponent(typeof(Motor))]
5 public class PlayerControls : MonoBehaviour {
6
7 public int selectedcamera = 0;
8 public cameraMotionScript cam;
9
10 private bool free = true;
11
12 private bool enab = true;
13
14 void FixedUpdate()
15 {
16
17 Motor motor = GetComponent<Motor>();
18
19 if (enab && motor.tim.startrace)
20 {
21
22 float accel = Input.GetAxis("Vertical");
23 float turn = Input.GetAxis("Horizontal");
24 float brake = Input.GetAxis("Jump");
25
26 motor.Move(turn, accel, 0f, 0f);
27 motor.HandBrake(Input.GetAxis("Fire1"));
28
29 }
30 else
31 {
32 motor.Move(0, 0, 1f, 0f);
33 }
34
35 if (Input.GetAxis("Camera") == 0)
36 {
37 free = true;
38 }
39 if (free && Input.GetAxis("Camera") == 1)
40 {
41 free = false;
42 selectedcamera++;
43 }
44 if (free && Input.GetAxis("Camera") == -1)
45 {
46 free = false;
47 selectedcamera--;
48 }
49 if (selectedcamera == 4)
50 {
51 selectedcamera = 0;
52 }
53 if (selectedcamera == -1)
54 {
55 selectedcamera = 3;
56 }
57
58 switch (selectedcamera)
59 {
60 case 0:
61 cam.distance = 15;
62 cam.height = 10;
63 cam.mode = 0;
64 break;
65 case 1:
66 cam.mode = 1;
67 break;
68 case 2:
69 cam.distance = 5;
70 cam.height = 50;
71 cam.mode = 0;
72 break;
73 case 3:
74 cam.mode = 2;
75 break;
76 }
77
78 }
79
80 public void finished()
81 {
82 enab = false;
83 cam.mode = 3;
84 }
85
86 }
2 using System.Collections;
3
4 [RequireComponent(typeof(Motor))]
5 public class PlayerControls : MonoBehaviour {
6
7 public int selectedcamera = 0;
8 public cameraMotionScript cam;
9
10 private bool free = true;
11
12 private bool enab = true;
13
14 void FixedUpdate()
15 {
16
17 Motor motor = GetComponent<Motor>();
18
19 if (enab && motor.tim.startrace)
20 {
21
22 float accel = Input.GetAxis("Vertical");
23 float turn = Input.GetAxis("Horizontal");
24 float brake = Input.GetAxis("Jump");
25
26 motor.Move(turn, accel, 0f, 0f);
27 motor.HandBrake(Input.GetAxis("Fire1"));
28
29 }
30 else
31 {
32 motor.Move(0, 0, 1f, 0f);
33 }
34
35 if (Input.GetAxis("Camera") == 0)
36 {
37 free = true;
38 }
39 if (free && Input.GetAxis("Camera") == 1)
40 {
41 free = false;
42 selectedcamera++;
43 }
44 if (free && Input.GetAxis("Camera") == -1)
45 {
46 free = false;
47 selectedcamera--;
48 }
49 if (selectedcamera == 4)
50 {
51 selectedcamera = 0;
52 }
53 if (selectedcamera == -1)
54 {
55 selectedcamera = 3;
56 }
57
58 switch (selectedcamera)
59 {
60 case 0:
61 cam.distance = 15;
62 cam.height = 10;
63 cam.mode = 0;
64 break;
65 case 1:
66 cam.mode = 1;
67 break;
68 case 2:
69 cam.distance = 5;
70 cam.height = 50;
71 cam.mode = 0;
72 break;
73 case 3:
74 cam.mode = 2;
75 break;
76 }
77
78 }
79
80 public void finished()
81 {
82 enab = false;
83 cam.mode = 3;
84 }
85
86 }