-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayerController.cs
More file actions
133 lines (116 loc) · 3.83 KB
/
Copy pathPlayerController.cs
File metadata and controls
133 lines (116 loc) · 3.83 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
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class PlayerController : MonoBehaviour
{
public float xRange = 9.0f;
public float zRange = 3.5f;
private float speed = 0.3f;
private float startDelay = 0.5f;
private float repeatRate = 0.25f;
private Rigidbody playerRb;
public GameObject projectilePrefab;
private int health = 10;
public TextMeshProUGUI healthText;
public bool isGameActive = true;
public ParticleSystem smallExplosion;
public ParticleSystem largeExplosion;
public ParticleSystem trail;
public AudioClip fireLaser;
public AudioClip ouchie;
public AudioClip fuckingDead;
private AudioSource playerAudio;
// Start is called before the first frame update
void Start()
{
InvokeRepeating("SpawnBullet", startDelay, repeatRate);
playerRb = GetComponent<Rigidbody>();
playerAudio = GetComponent<AudioSource>();
}
// Update is called once per frame
void FixedUpdate()
{
if (transform.position.x < -xRange)
{
transform.position = new Vector3(-xRange, transform.position.y, transform.position.z);
}
if (transform.position.x > 4)
{
transform.position = new Vector3(4, transform.position.y, transform.position.z);
}
if (transform.position.z < -zRange)
{
transform.position = new Vector3(transform.position.x, transform.position.y, -zRange);
}
if (transform.position.z > zRange)
{
transform.position = new Vector3(transform.position.x, transform.position.y, zRange);
}
float horizontalInput = Input.GetAxis("Horizontal");
float verticalInput = Input.GetAxis("Vertical");
if (isGameActive == true) {
transform.Translate(-Vector3.up * speed * horizontalInput);
transform.Translate(Vector3.right * speed * verticalInput);
}
}
void SpawnBullet()
{
if (isGameActive == true)
{
Instantiate(projectilePrefab, transform.position, projectilePrefab.transform.rotation);
playerAudio.PlayOneShot(fireLaser, 0.25f);
}
}
void OnTriggerEnter(Collider other)
{
if (isGameActive == true)
{
if (other.gameObject.CompareTag("Attack"))
{
Destroy(other.gameObject);
health = health - 1;
healthText.text = "Health: " + health;
StartCoroutine(boom());
playerAudio.PlayOneShot(ouchie, 1.0f);
}
if (other.gameObject.CompareTag("Fat"))
{
Destroy(other.gameObject);
health = health - 4;
healthText.text = "Health: " + health;
StartCoroutine(boom());
playerAudio.PlayOneShot(ouchie, 1.0f);
}
if (health < 1)
{
GameOver();
//Debug.Log("get rekt");
}
//Debug.Log(health);
}
}
void GameOver()
{
StartCoroutine(ded());
}
IEnumerator ded()
{
trail.Stop();
smallExplosion.Play();
largeExplosion.Play();
playerAudio.PlayOneShot(fuckingDead, 1.0f);
isGameActive = false;
yield return new WaitForSeconds(1f);
SceneManager.LoadScene("GameOver");
//SceneManager.LoadScene(SceneManager.GetActiveScene().name);
}
IEnumerator boom()
{
smallExplosion.Play();
yield return new WaitForSeconds(1f);
smallExplosion.Stop();
}
}