-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplayerControl.cs
More file actions
57 lines (39 loc) · 1.66 KB
/
playerControl.cs
File metadata and controls
57 lines (39 loc) · 1.66 KB
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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class playerControl : MonoBehaviour
{
public string inputID;
public Camera mainCamera;
public Camera hoodCamera;
public KeyCode switchKey;
private float speed = 10.0f;
private float turnSpeed =30.0f;
private float horizontalInput;
private float verticalInput;
// Start is called before the first frame update
void Start()
{
// start
}
// Update is called once per frame
void Update()
{
horizontalInput = Input.GetAxis("Horizontal" + inputID);
verticalInput = Input.GetAxis("Vertical" + inputID);
// we will move forward the vehicle.
//transform.Translate(0,0,1);
// transform.Translate(Vector3.forward); // this also do the same as above line vector3.forward.
transform.Translate(Vector3.forward * Time.deltaTime * speed * verticalInput);
// transform.Translate(Vector3.right * Time.deltaTime * turnSpeed*horizontalInput); // here it slides left and right depends on the left and right arrow control keys.
// we will try to rotate instead of sliding.
transform.Rotate(Vector3.up * Time.deltaTime * turnSpeed*horizontalInput);
if(Input.GetKeyDown(switchKey))
{
mainCamera.enabled = !mainCamera.enabled;
hoodCamera.enabled = !hoodCamera.enabled;
}
//transform.Translate(Vector3.right * Time.deltaTime * turnSpeed * verticalInput);
//transform.Translate(Vector3.left * Time.deltaTime * turnSpeed * horizontalInput); // if I press left it goes right --> left = -1
}
}