-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlayer.cs
80 lines (63 loc) · 2.17 KB
/
Player.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Player : MonoBehaviour {
[SerializeField]
private GameObject _laserPrefab;
public bool canTriple = false;
private float fireRate = 0.25f;
private float nextRate = 0.0f;
public float speed = 5.0f;
// Use this for initialization
void Start () {
transform.position = new Vector3(0, 0, 0);
}
// Update is called once per frame
void Update () {
movement();
if (Input.GetKeyDown(KeyCode.Space) || Input.GetMouseButton(0))
{
shoot();
}
}
private void shoot()
{
if (Time.time > nextRate)
{
if (canTriple == true)
{
Instantiate(_laserPrefab, transform.position + new Vector3(0, 0.95f, 0), Quaternion.identity);
Instantiate(_laserPrefab, transform.position + new Vector3(-0.55f, -0.03f, 0), Quaternion.identity);
Instantiate(_laserPrefab, transform.position + new Vector3(0.57f, -0.04f, 0), Quaternion.identity);
}
else
{
Instantiate(_laserPrefab, transform.position + new Vector3(0, 0.95f, 0), Quaternion.identity);
}
nextRate = Time.time + fireRate;
}
}
private void movement()
{
float horizontalInput = Input.GetAxis("Horizontal");
transform.Translate(Vector3.right * Time.deltaTime * speed * horizontalInput);
float verticalInput = Input.GetAxis("Vertical");
transform.Translate(Vector3.up * Time.deltaTime * speed * verticalInput);
if (transform.position.y > 0)
{
transform.position = new Vector3(transform.position.x, 0, 0);
}
else if (transform.position.y < -4.1f)
{
transform.position = new Vector3(transform.position.x, -4.1f, 0);
}
if (transform.position.x > 6.0f)
{
transform.position = new Vector3(6.0f, transform.position.y, 0);
}
else if (transform.position.x < -6.3f)
{
transform.position = new Vector3(-6.3f, transform.position.y, 0);
}
}
}