1 using System.Collections;
2 using System.Collections.Generic;
35 Turret = GameObject.FindGameObjectWithTag (
"TurretObject");
36 Cannon = GameObject.FindGameObjectWithTag (
"CannonObject");
37 FrontWheels = GameObject.FindGameObjectsWithTag (
"FrontWheelsObject");
38 BackWheels = GameObject.FindGameObjectsWithTag (
"BackWheelsObject");
39 FrontTurningWheels = GameObject.FindGameObjectsWithTag (
"FrontWheelsTurningObject");
56 if (Input.GetKeyDown (KeyCode.R)) {
57 SceneManager.LoadScene (SceneManager.GetActiveScene ().name);
80 if (Input.GetKey(KeyCode.D))
82 horizontal = Input.GetKey(KeyCode.D) ? 0.45f : 0;
85 horizontal = Input.GetKey(KeyCode.A) ? -0.45f : 0;
98 if (Input.GetKey (KeyCode.W)) {
104 FrontWheels[0].transform.Rotate(RotateForward, 0, 0);
105 FrontWheels[1].transform.Rotate(RotateForward, 0, 0);
107 else if (Input.GetKey (KeyCode.S)) {
113 FrontWheels[0].transform.Rotate(-RotateForward, 0, 0);
114 FrontWheels[1].transform.Rotate(-RotateForward, 0, 0);
129 Vector3 front_rotationAmount = transform.rotation.eulerAngles;
130 front_rotationAmount.y += current_rot;
132 SteeringLeft.rotation = Quaternion.Euler(front_rotationAmount);
133 SteeringRight.rotation = Quaternion.Euler(front_rotationAmount);
144 if (Input.GetKey (KeyCode.W)) {
150 BackWheels[0].transform.Rotate(RotateBackward, 0, 0);
151 BackWheels[1].transform.Rotate(RotateBackward, 0, 0);
153 else if (Input.GetKey (KeyCode.S)) {
159 BackWheels[0].transform.Rotate(-RotateBackward, 0, 0);
160 BackWheels[1].transform.Rotate(-RotateBackward, 0, 0);
180 if (Input.GetKey (KeyCode.UpArrow)) {
181 Debug.Log (
"Up Arrow Key Pressed");
183 float currentRotationZ = Cannon.transform.rotation.z * 100;
187 if (currentRotationZ <= -70){
191 currentRotationZ = -70 / 100;
196 currentRotationZ /= 100;
197 currentRotationZ -= tilt;
200 Cannon.transform.Rotate (0, 0, currentRotationZ);
202 else if (Input.GetKey (KeyCode.DownArrow)) {
203 Debug.Log (
"Down Arrow Key Pressed");
205 float currentRotationZ = Cannon.transform.rotation.z * 100;
209 if (currentRotationZ >= 0){
213 currentRotationZ = 0 / 100;
218 currentRotationZ /= 100;
219 currentRotationZ -= tilt;
222 Cannon.transform.Rotate (0, 0, -currentRotationZ);
239 if (Input.GetKey (KeyCode.LeftArrow)) {
240 Debug.Log (
"Left Arrow Key Pressed");
244 Turret.transform.Rotate (0, -rotateLeft, 0);
247 else if (Input.GetKey (KeyCode.RightArrow)) {
248 Debug.Log (
"Right Arrow Key Pressed");
252 Turret.transform.Rotate (0, rotateRight, 0);
271 if (Input.GetKey (KeyCode.W)) {
273 Debug.Log (
"W Key is pressed");
275 var MoveForward = Time.deltaTime *
TankSpeed;
280 else if (Input.GetKey (KeyCode.S)) {
282 Debug.Log (
"S Key is pressed");
284 var MoveBackward = Time.deltaTime *
TankSpeed;
290 if (Input.GetKey (KeyCode.A)) {
292 Debug.Log (
"A Key is pressed");
294 var TurnLeft = Time.deltaTime *
TankSpeed;
298 else if (Input.GetKey (KeyCode.D)) {
300 Debug.Log (
"D Key is pressed");
302 var TurnRight = Time.deltaTime *
TankSpeed;
316 transform.Translate (movement, 0, 0);
327 transform.Rotate (0, movement, 0);
void Start()
Initalize at the beginning of the game
void CannonRotation()
How far the cannon should rotate up and to its rest position. Max for up position is vertical (90 deg...
void WheelSteering()
The steering for left or right to determine how far it should also rotate.
void HorizontalWheel()
The front wheels will go either rotate left or right by 45 degrees.
void ForwardBackward(float movement)
When the W or S key is pressed, the tank will move forward or backward respectively ...
GameObject [] FrontTurningWheels
void LeftRight(float movement)
When the A or D key is pressed, the tank will move left or right respectively
void Update()
Update is called once per frame
void FrontWheelMovement()
The Front wheels should rotate forward/backward and should rotate with an angle of maxiumum of 45 to ...
void BackWheelMovement()
The back wheels should rotate and also accelerate/decelerate the tank
GameObject [] FrontWheels
void TankMovement()
This is called in the update function. All funcitonality is done here for the tank movement like movi...
void TurretRotation()
Will rotate the turret left or right when the user press left or right arrow keys ...