mestiez / ppg-snippets

a number of useful code snippets that should help users write People Playground mods

Home Page:https://www.studiominus.nl/ppg-modding/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

how to play sound on gun shot (HELP PLEASE)

xzripper opened this issue · comments

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

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();
            };
        }
    }
}