-
Notifications
You must be signed in to change notification settings - Fork 0
/
GunAssaultrifle.cs
105 lines (99 loc) · 3.55 KB
/
GunAssaultrifle.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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GunAssaultrifle : MonoBehaviour
{
GameObject thePlayer;
GunInfo EquippedGun;
bool readytoshoot = true;
float spreadvar;
IEnumerable<int> multishotcount;
bool even;
GameObject bullet;
public Sprite icon;
public Sprite specialicon;
public int maxstacks = 30;
public int stacks = 0;
public float damageperstack = 50;
public float reloadperstack = .05f;
// Start is called before the first frame update
void Awake(){
GetComponent<gameinitiater>().funcs.Add(Initer);
}
void Initer()
{
GunUiInfo info = new GunUiInfo(icon,specialicon,"Soulstealer", "bullets give 5hp regen, holding the fire button slows firerate but increases damage by 50 and doubles damage dealt");
GunInfo rifle = new GunInfo("rifle",0, 60, .2f, 30, 1, 30, 1.5f, GetComponent<GunClasses>().single_shot_effect, GetComponent<GunClasses>().bullet, true, 0, RifleReload, info, 3000);
EquippedGun = rifle;
GunInfo.Guns.Add(rifle.name, rifle);
}
// Update is called once per frame
public void RifleReload(GameObject thePlayer){
this.thePlayer = thePlayer;
if(Input.GetMouseButton(0))
{
if(readytoshoot){
readytoshoot = false;
RifleShoot();
stacks +=1;
Invoke("reload", EquippedGun.FireRate + (stacks * reloadperstack));
print(stacks +": " +reloadperstack * stacks);
}
}
else{
stacks = 0;
}
}
public void RifleShoot()
{
bullet = Instantiate(EquippedGun.bullet, new Vector3(thePlayer.transform.position.x, thePlayer.transform.position.y, -9), thePlayer.transform.rotation * Quaternion.Euler(0, 0, spreadvar));
StartCoroutine(RifleBulletModifier(bullet, EquippedGun));
thePlayer.transform.Translate(new Vector2(0, -EquippedGun.recoil * Time.deltaTime));
}
public IEnumerator RifleBulletModifier(GameObject bullet, GunInfo shotby){
if( shotby.BulletSpeed > 140){
bullet.GetComponent<MoveForward>().enableraycast = true;
}
while(!bullet.GetComponent<MoveForward>().hit){
bullet.transform.Translate(new Vector2(0, 1) * shotby.BulletSpeed * Time.deltaTime);
yield return new WaitForEndOfFrame();
}
Collider2D enemy = bullet.GetComponent<MoveForward>().enemyhit;
if (enemy.CompareTag("enemy") )
{
float damage;
bool Crit = Chance(EquippedGun.CC);
if (Crit)
{
damage = ((EquippedGun.Damage + (stacks * damageperstack)) * 2) * EquippedGun.CD;
}
else
{
damage = ((EquippedGun.Damage + (stacks * damageperstack)) *2);
}
if(thePlayer.GetComponent<mobeffects>().hp+5 > thePlayer.GetComponent<mobeffects>().maxhp){
thePlayer.GetComponent<mobeffects>().hp += 5;
}
enemy.GetComponent<mobeffects>().sethp((int)(enemy.GetComponent<mobeffects>().hp - damage), null, EquippedGun.HitEffect);
}
if (enemy.tag != "Player")
{
Destroy(bullet);
}
}
public bool Chance(float chance)
{
int random = UnityEngine.Random.Range(1, 100);
if (random <= chance)
{
return true;
}
else
{
return false;
}
}
public void reload(){
readytoshoot = true;
}
}