-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayerController_2.cs
More file actions
52 lines (39 loc) · 1.5 KB
/
PlayerController_2.cs
File metadata and controls
52 lines (39 loc) · 1.5 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
using UnityEngine;
public class PlayerController_2 : MonoBehaviour
{
public float speed;
private float xRange = 20;
private float zRange = 17;
private float horizontalInput;
private float verticalInput;
public GameObject projectilePrefab;
void Update()
{
horizontalInput = Input.GetAxis("Horizontal");
// verticalInput = Input.GetAxis("Vertical");
verticalInput = Input.GetAxis("Vertical");
transform.Translate(Vector3.forward*verticalInput * speed*Time.deltaTime);
if (transform.position.z < -2)
{
transform.position = new Vector3(transform.position.x, transform.position.y, -2);
}
if (transform.position.z > zRange)
{
transform.position = new Vector3(transform.position.x, transform.position.y, 17);
}
transform.Translate(Vector3.right * horizontalInput * speed * Time.deltaTime);
if (transform.position.x < -xRange)
{
transform.position = new Vector3(-xRange, transform.position.y, transform.position.z);
}
if (transform.position.x > xRange)
{
transform.position = new Vector3(xRange, transform.position.y, transform.position.z);
}
if (Input.GetKeyDown(KeyCode.Space))
{
//Launch a projectile from the player
Instantiate(projectilePrefab, transform.position, projectilePrefab.transform.rotation);
}
}
}