-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOverWorldTank.cs
65 lines (47 loc) · 1.28 KB
/
OverWorldTank.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class OverWorldTank : MonoBehaviour {
[Header("PlayerControls")]
public KeyCode left;
public KeyCode right;
public KeyCode forward;
public KeyCode backward;
public KeyCode fireWeapon;
private float XMovement;
private float ZMovement;
private bool moved;
public float movementSpeed = 5f;
public GameObject tankParent;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
//*** Reset Movement
XMovement = 0f;
ZMovement = 0f;
moved = false;
//*** Move from left to right
if(Input.GetKey(left)){
moved = true;
transform.Rotate((Vector3.up * Time.deltaTime * movementSpeed) * -2f);
}else if(Input.GetKey(right)){
moved = true;
transform.Rotate((Vector3.up * Time.deltaTime *movementSpeed) * 2f);
}
//*** Move forward and Back
if(Input.GetKey(forward)){
moved = true;
ZMovement = movementSpeed;
}else if(Input.GetKey(backward)){
moved = true;
ZMovement = movementSpeed * -1f;
}
//*** Move Tank
if(moved)
transform.Translate(new Vector3(XMovement,0f,ZMovement));
//*** Set Tank parent to Match our players Position
tankParent.transform.position = this.gameObject.transform.position;
}
}