-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShotgun.cs
More file actions
58 lines (49 loc) · 1.37 KB
/
Shotgun.cs
File metadata and controls
58 lines (49 loc) · 1.37 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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Shotgun : MonoBehaviour
{
public Rigidbody player;
public Transform cam;
public float reloadCooldown;
private float remainingCooldown;
public int magazine;
private int bullets;
public float recoil;
public Transform shotgunTip;
//public ParticleSystem particles;
public Animator animator;
void Start()
{
bullets = magazine;
remainingCooldown = reloadCooldown;
}
void Update()
{
Debug.Log(bullets);
if (bullets > 0)
{
if (Input.GetMouseButtonDown(1))
{
player.AddForce(-cam.forward * recoil, ForceMode.Impulse);
bullets -= 1;
if (bullets == 1)
animator.SetTrigger("shot");
}
}
else if (bullets == 0)
{
remainingCooldown -= Time.deltaTime;
if (remainingCooldown != reloadCooldown)
{
animator.SetBool("reloading", true);
}
if (remainingCooldown <= 0)
{
bullets = magazine;
remainingCooldown = reloadCooldown;
animator.SetBool("reloading", false);
}
}
}
}