Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by MSB · Jun 18, 2013 at 05:04 PM · soundplayno

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!

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

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.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image MSB · Jun 25, 2013 at 04:11 PM 0
Share

Thanks I'll give that a shot when I can!

avatar image SpecticalPro · Jun 25, 2013 at 04:51 PM 0
Share

I believe he is right, since if you debug.log(Input.GetButtonDown("Fire1")) inside of your shooting off function, this returns false.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

16 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Audio Playing upon death 1 Answer

gameObject to play sound on deletion, won't work... 1 Answer

How to Play a Sound from an Array from an Overloaded Method? 1 Answer

audio trigger keydown 1 Answer

Returning to menu screen through pause menu. No sound. 3 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges