so I have been working on this game and I need this gun to make a sound but if I add a sound I know I can just make it semi-automatic and play sound after sound but I need it to be fully automatic and its really pissing me off because if I just fire it once with sound clip it plays fine but if I hold it it makes a high pitch spastic sound
How are you playing the sounds?
Your code must be wrong.
i never coded in for it to make sound
my code:
var firing : boolean = false;
var accuracy : float;
private var bulletCaseGenerator : Transform;
private var bulletTraceGenerator : Transform;
private var muzzleFlashGenerator : Transform;
private var bulletCaseGeneratorScript : bulletCaseGenerator;
private var bulletTraceGeneratorScript : bulletTraceGenerator;
private var muzzleFlashGeneratorScript : muzzleFlashGenerator;
function Start(){
bulletCaseGenerator = transform.Find("bulletCaseGenerator");
bulletTraceGenerator = transform.Find("bulletTraceGenerator");
muzzleFlashGenerator = transform.Find("muzzleFlashGenerator");
bulletCaseGeneratorScript = bulletCaseGenerator.GetComponent("bulletCaseGenerator");
bulletTraceGeneratorScript = bulletTraceGenerator.GetComponent("bulletTraceGenerator");
muzzleFlashGeneratorScript = muzzleFlashGenerator.GetComponent("muzzleFlashGenerator");
firing = false;
//accuracy = 0.9;
}
function Update () {
bulletCaseGeneratorScript.on = firing;
bulletTraceGeneratorScript.on = firing;
muzzleFlashGeneratorScript.on = firing;
bulletTraceGeneratorScript.accuracy = accuracy;
firing = false;
}
function Fire(){
firing = true;
}
function SetAccuracy(accuracyValue : float){
accuracy = accuracyValue;
}
In your shoot function, where you shoot your bullets, add the code to play your sound there. that way every time you shoot the sound will be played.
that is what i did but since it is a case of you hold it it is a automatic rifle every time you hold it down it makes a spastic sound
Do you mean that the sound is started over and over very fast making it bad?
If that’s the case, then before you play the sound make a check to see if the shooting sound isn’t playing, it is isn’t then play, otherwise don’t play it for that shot.