-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshoot_object.cs
81 lines (66 loc) · 2.02 KB
/
shoot_object.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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class shoot_object : MonoBehaviour
{
public Rigidbody projectile;
public GameObject trigger;
public float projectile_Speed;
public Transform end_of_barrel;
public GameObject muzzleFlash;
public bool test;
public int reload_time;
public bool reloaded;
public Collider reloadCollider;
//SFX
private AudioSource fireSFX;
public AudioSource reloadSFX;
private void Start()
{
fireSFX = GetComponent<AudioSource>();
reloaded = false;
trigger.SetActive(false);
reloadCollider.enabled = true;
if (test == true)
{
Trigger_Pulled();
}
}
private void Update()
{
if(test == true)
{
if(reloaded == false)
{
StartCoroutine(Reload());
}
else
{
Trigger_Pulled();
}
}
}
public void Trigger_Pulled()
{
if (reloaded == true)
{
Debug.Log("Trigger Pulled");
reloaded = false;
fireSFX.Play();
trigger.SetActive(false);
GameObject muzzle_clone = (GameObject)Instantiate(muzzleFlash, end_of_barrel.transform.position, end_of_barrel.transform.rotation);
muzzle_clone.transform.Rotate(0, -90, 0, Space.World);
Rigidbody projectile_clone = (Rigidbody)Instantiate(projectile, end_of_barrel.position, end_of_barrel.rotation);
projectile_clone.velocity = end_of_barrel.forward * projectile_Speed;
Destroy(muzzle_clone, 5);
reloadCollider.enabled = true;
}
}
public IEnumerator Reload()
{
reloadSFX.Play();
reloadCollider.enabled = false;
yield return new WaitForSeconds(reload_time);
trigger.SetActive(true);
}
}