how to play sound on gun shot (HELP PLEASE)
xzripper opened this issue · comments
Ivan commented
using System;
using UnityEngine;
// GunSFX Mod.
namespace GunSFX {
public class GunSFX {
public static void Main() {
string[] ShotSounds = {"sfx\\OneShot.mp3", "sfx\\SecondShot.mp3", "sfx\\ThirdShot.mp3"};
var RandomInstance = new System.Random();
var ChosenShotSound = ShotSounds[RandomInstance.Next(ShotSounds.Length)];
ModAPI.OnGunShot += (Sender, Gun) => {
var ShotSound = ModAPI.LoadSound(ChosenShotSound);
Gun.GetComponent<AudioSource>().clip = ShotSound;
Gun.GetComponent<AudioSource>().Play();
};
}
}
}
Error please help
Ivan commented
using System;
using UnityEngine;
// GunSFX Mod.
namespace GunSFX {
public class GunSFX {
public static void Main() {
ModAPI.Notify("Hi!");
string[] ShotSounds = {"sfx/OneShot.mp3", "sfx/SecondShot.mp3", "sfx/ThirdShot.mp3"};
var RandomInstance = new System.Random();
var ChosenShotSound = ShotSounds[RandomInstance.Next(ShotSounds.Length)];
var ShotSound = ModAPI.LoadSound(ChosenShotSound);
ModAPI.OnGunShot += (sender, gun) => {
ModAPI.Notify("Shot.");
ModAPI.Notify(ChosenShotSound);
gun.GetComponent<AudioSource>().clip = ShotSound;
gun.GetComponent<AudioSource>().Play();
};
}
}
}