-
Notifications
You must be signed in to change notification settings - Fork 0
/
Weapon.cs
91 lines (69 loc) · 2.43 KB
/
Weapon.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
using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;
[CreateAssetMenu]
public class Weapon : ScriptableObject
{
// våben data:
public bool isAuto;
public bool isMeele;
public float meleeRadius;
public int Ammo;
public int startAmmo;
public int damage = 1;
public int bulletsPerShot;
public float bulletSpread;
public float firerate;
public float reloadTime;
public float shakeDureation;
public float shakeAmount;
public string soundName;
// prefab ref:
public Bullet bullet;
//Sprite ref:
public Sprite weaponSprite;
public Sprite sideSprite;
public Sprite ammoSprite;
// værdi tildeles i script
public Transform meleeHitBoxPos;
public Transform firePoint;
private void Awake(){
Ammo = startAmmo;
}
// angrib metode
public void Shoot(string targetTag){
// skyde våben:
if (!isMeele && Ammo > 0){
// cam shake
Camera.main.GetComponent<cameraShake>().ShakeCamera(shakeDureation, shakeAmount);
FindObjectOfType<AudioManager>().Play(soundName);
// instantiate alle skud.
for (int i = 0; i < bulletsPerShot; i++){
Quaternion rot = Quaternion.Euler(0, 0, firePoint.rotation.z + Random.Range(-bulletSpread, bulletSpread));
Bullet _bullet = Instantiate(bullet, firePoint.position, firePoint.rotation * rot);
_bullet.targetTag = targetTag;
_bullet.damage = damage;
}
Ammo -= 1;
}
// Meele våben:
if (isMeele){
Collider2D[] results = Physics2D.OverlapCircleAll(meleeHitBoxPos.position, meleeRadius, LayerMask.GetMask("Enemy"));
FindObjectOfType<AudioManager>().Play(soundName);
if (results.Length > 0){
// kald på cam shake og lyd
Camera.main.GetComponent<cameraShake>().ShakeCamera(shakeDureation, shakeAmount);
FindObjectOfType<AudioManager>().Play("bathit");
}
// gør skade på alle fjender i radius
foreach (Collider2D hit in results){
hit.gameObject.GetComponent<EnemyBehavior>().takeDMG(damage);
}
}
}
// reload våbnet
public void Reload(){
Ammo = startAmmo;
}
}