Add reload

This commit is contained in:
2023-08-04 15:50:02 -07:00
parent e396a34d1b
commit d28eb01c25
5 changed files with 37 additions and 8 deletions

BIN
Audio/SFX/reload.mp3 Normal file

Binary file not shown.

View File

@@ -0,0 +1,19 @@
[remap]
importer="mp3"
type="AudioStreamMP3"
uid="uid://batlteciilc8s"
path="res://.godot/imported/reload.mp3-863228f3aba19bac75de4e7e8529afcc.mp3str"
[deps]
source_file="res://Audio/SFX/reload.mp3"
dest_files=["res://.godot/imported/reload.mp3-863228f3aba19bac75de4e7e8529afcc.mp3str"]
[params]
loop=false
loop_offset=0
bpm=0
beat_count=0
bar_beats=4

View File

@@ -1,8 +1,7 @@
[gd_scene load_steps=11 format=3 uid="uid://dae1bs2yqqt5l"] [gd_scene load_steps=10 format=3 uid="uid://dae1bs2yqqt5l"]
[ext_resource type="Script" path="res://Scripts/Player.cs" id="1_jsq3s"] [ext_resource type="Script" path="res://Scripts/Player.cs" id="1_jsq3s"]
[ext_resource type="Environment" uid="uid://c1i78mwq3ug2f" path="res://Scenes/Enivornment.tres" id="2_t03qe"] [ext_resource type="Environment" uid="uid://c1i78mwq3ug2f" path="res://Scenes/Enivornment.tres" id="2_t03qe"]
[ext_resource type="AudioStream" uid="uid://cupjwk5q538g2" path="res://Audio/SFX/gunshot.mp3" id="3_5mglu"]
[ext_resource type="Script" path="res://Scripts/SoundEffects.cs" id="4_fmvkw"] [ext_resource type="Script" path="res://Scripts/SoundEffects.cs" id="4_fmvkw"]
[ext_resource type="PackedScene" uid="uid://cc5emorildoar" path="res://Scenes/Gun.tscn" id="5_sb1dv"] [ext_resource type="PackedScene" uid="uid://cc5emorildoar" path="res://Scenes/Gun.tscn" id="5_sb1dv"]
[ext_resource type="Script" path="res://Scripts/Gun.cs" id="6_48ohb"] [ext_resource type="Script" path="res://Scripts/Gun.cs" id="6_48ohb"]
@@ -40,11 +39,8 @@ fov = 60.0
transform = Transform3D(0.125, 0, 0, 0, 0.125, 0, 0, 0, 0.125, 0, 0, 0) transform = Transform3D(0.125, 0, 0, 0, 0.125, 0, 0, 0, 0.125, 0, 0, 0)
target_position = Vector3(0, 0, -1000) target_position = Vector3(0, 0, -1000)
[node name="AudioStreamPlayer3D" type="AudioStreamPlayer3D" parent="Pivot/Camera3D"] [node name="SFXPlayer" type="AudioStreamPlayer3D" parent="Pivot/Camera3D"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -1.10748, -0.0718701) transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -1.10748, -0.0718701)
stream = ExtResource("3_5mglu")
volume_db = -13.823
max_db = -5.0
max_polyphony = 8 max_polyphony = 8
script = ExtResource("4_fmvkw") script = ExtResource("4_fmvkw")
@@ -78,6 +74,7 @@ label_settings = SubResource("LabelSettings_3d4s1")
horizontal_alignment = 1 horizontal_alignment = 1
vertical_alignment = 1 vertical_alignment = 1
[connection signal="FireGun" from="Gun" to="Pivot/Camera3D/AudioStreamPlayer3D" method="OnFireGun"] [connection signal="FireGun" from="Gun" to="Pivot/Camera3D/SFXPlayer" method="OnFireGun"]
[connection signal="FireGun" from="Gun" to="CanvasLayer" method="UpdateCurrentAmmo"] [connection signal="FireGun" from="Gun" to="CanvasLayer" method="UpdateCurrentAmmo"]
[connection signal="ReloadGun" from="Gun" to="Pivot/Camera3D/SFXPlayer" method="OnReload"]
[connection signal="ReloadGun" from="Gun" to="CanvasLayer" method="UpdateCurrentAmmo"] [connection signal="ReloadGun" from="Gun" to="CanvasLayer" method="UpdateCurrentAmmo"]

View File

@@ -54,7 +54,7 @@ public partial class Gun : Node3D
private async Task Reload() private async Task Reload()
{ {
_reloading = true; _reloading = true;
await ToSignal(GetTree().CreateTimer(0.3f), "timeout"); await ToSignal(GetTree().CreateTimer(0.5f), "timeout");
_reloading = false; _reloading = false;
} }

View File

@@ -2,8 +2,21 @@ using Godot;
public partial class SoundEffects : AudioStreamPlayer3D public partial class SoundEffects : AudioStreamPlayer3D
{ {
private string _fireSfx = "res://Audio/SFX/gunshot.mp3";
private string _reloadSfx = "res://Audio/SFX/reload.mp3";
public void OnFireGun() public void OnFireGun()
{ {
var audioStream = ResourceLoader.Load<AudioStream>(_fireSfx);
Stream = audioStream;
Play();
}
public void OnReload()
{
var audioStream = ResourceLoader.Load<AudioStream>(_reloadSfx);
Stream = audioStream;
Play(); Play();
} }
} }