- Home /
Sound Effect won't play!
First off I'd like to thank everyone who's been helping so far, you've been a big help!...now for today's issue :P
In this game you hit the "fire1" button to shoot a projectile and hold "Jump" to bring up the shield...then releasing "Jump" turns the shield off. Whilst the shield is up, shooting projectiles is disabled.
I've got this bit of code attached to the shield (NOTE, Yep I misspelt shield :P)
if(Input.GetButtonDown("Jump")){
Sheildclone = Instantiate(Sheild, transform.position, transform.rotation);
gameObject.Find("GunL").SendMessage("SheildON");
gameObject.Find("GunR").SendMessage("SheildON");
}
if(Input.GetButtonUp("Jump")){
Destroy (Sheildclone);
gameObject.Find("GunL").SendMessage("SheildOFF");
gameObject.Find("GunR").SendMessage("SheildOFF");
}
}
The shield turns on and off fine and sends the signal too the guns -
var sheild : boolean = false;
var projectile : Rigidbody;
var speed = 20;
var NoShot: AudioClip;
var Shot: AudioClip;
function Update () {
if(sheild ==false){
ShootingON();
if(sheild ==true){
ShootingOFF();
}
}
}
function ShootingON () {
if(sheild ==false){
if (Input.GetButtonDown("Fire1")) {
var clone : Rigidbody;
clone = Instantiate(projectile, transform.position, transform.rotation);
clone.velocity = transform.TransformDirection (Vector3.forward * speed);
audio.PlayOneShot(Shot);
clone.tag = "Projectile";
}
}
}
function ShootingOFF () {
if(sheild ==true){
if (Input.GetButtonDown("Fire1")) {
Debug.Log ("NO SHOT");
audio.PlayOneShot(NoShot);
}
}
}
function SheildON () {
sheild = true;
}
function SheildOFF () {
sheild = false;
}
When the Shield is off, sure enough you can shoot and the "Shot" sound effect plays. However when the Shield is on, Shooting is turned off but the "NoShot" sound effect won't play...
EDIT - Just added Debug.Log ("NO SHOT"); and that isn't printing either..it's odd that it stops the ability to shoot but won't make the sound/print a log.
Any light shed on this would be great!
Answer by MissingSemicolon · Jun 25, 2013 at 11:22 AM
Wouldn't you have to check if both the space bar & the fire button are being pressed?
so like:
if((Input.GetButtonDown("Fire1")) && (Input.GetButtonDown("Jump")))
Give that a try and see if it helps.
You may need to have a play with GetButton/GetKey to see if a combination of them will work.
I believe he is right, since if you debug.log(Input.GetButtonDown("Fire1")) inside of your shooting off function, this returns false.