-
Notifications
You must be signed in to change notification settings - Fork 0
/
GunScript.cs
114 lines (110 loc) · 3.55 KB
/
GunScript.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
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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GunScript : MonoBehaviour
{
[SerializeField] GameObject playScreen;
[SerializeField] GameObject namlu;
[SerializeField] GameObject bullet;
[SerializeField] AudioSource shoot;
public int bulletCount = 0;
public int bulletCurrent;
public int bulletMax = 20;
public string gunType;
public void Update()
{
if (Input.GetMouseButtonDown(0) && playScreen.gameObject.activeInHierarchy && bulletCount >= 1)
{
Shoot();
}
else if (bulletCount <= 0)
{
Reload();
}
}
private void Awake()
{
Debug.Log(gunType);
switch (gunType)
{
case "pistol":
DataManager.Instance.ammoPistol = bulletCurrent;
break;
case "shotgun":
DataManager.Instance.ammoShotty = bulletCurrent;
break;
case "laser":
DataManager.Instance.ammoLaser = bulletCurrent;
break;
case "shuriken":
DataManager.Instance.ammoShuriken = bulletCurrent;
break;
case "minigun":
DataManager.Instance.ammoMinigun = bulletCurrent;
break;
case "sword":
break;
}
}
void Shoot()
{
shoot.Play();
switch (gunType)
{
case "pistol":
DataManager.Instance.ammoPistol--;
bulletCurrent = DataManager.Instance.ammoPistol;
Instantiate(bullet, namlu.transform.position, namlu.transform.rotation);
bulletCount = bulletCurrent;
break;
case "shotgun":
Debug.Log("Shotgunfired");
DataManager.Instance.ammoShotty--;
bulletCurrent = DataManager.Instance.ammoShotty;
Instantiate(bullet, namlu.transform.position, namlu.transform.rotation);
bulletCount = bulletCurrent;
break;
case "laser":
DataManager.Instance.ammoLaser--;
bulletCurrent = DataManager.Instance.ammoLaser;
Instantiate(bullet, namlu.transform.position, namlu.transform.rotation);
bulletCount = bulletCurrent;
break;
case "shuriken":
DataManager.Instance.ammoShuriken--;
bulletCurrent = DataManager.Instance.ammoShuriken;
Instantiate(bullet, namlu.transform.position, namlu.transform.rotation);
bulletCount = bulletCurrent;
break;
case "minigun":
DataManager.Instance.ammoMinigun--;
bulletCurrent = DataManager.Instance.ammoMinigun;
Instantiate(bullet, namlu.transform.position, namlu.transform.rotation);
bulletCount = bulletCurrent;
break;
case "sword":
Instantiate(bullet, namlu.transform.position, namlu.transform.rotation);
break;
}
}
void Reload()
{
if(bulletMax >6)
{
bulletMax -= 6;
bulletCurrent += 6;
bulletCount = bulletCurrent;
}
else
{
bulletCurrent += bulletMax;
bulletMax = 0;
bulletCount = bulletCurrent;
}
if (bulletCurrent <= 0 || bulletMax <= 0)
{
bulletCurrent = 0;
bulletMax = 0;
}
}
}