• 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 EscTheCtrl · Jan 22, 2013 at 03:44 AM · fpssoundglitchbugsfiring

Sound not playing correctly And projectiles not firing Correctly...

So I started a FPS game a few days ago, and I just can't figure out a few bugs I have. My first problem is when I fire the gun the sound will play correctly, but if I fire again before the first sound finishes it will cut off the first sound clip and start over. Is there a way where I can get the sound to play over top of one another so that they can finish playing the entire sound clip? Here's what my code looks like; var projectile:Rigidbody; var Play:AudioClip;

 function Update ()
 {
     //Simple Bullet Physics
     if (Input.GetButtonDown ("Fire1")) 
     {
     
         //Instantiate the projectile at the position and rotation of this transform
         var clone : Rigidbody;
         clone = Instantiate(projectile, transform.position, transform.rotation);
         
         //Give the cloned obbject an initial velocity along the current
         //Object's Z axis
         clone.velocity = transform.TransformDirection (Vector3.forward * 50);    
         
         //Heres where the sound Comes in
         audio.Play();
         
     }    
 
 }

My second problem is when I'm looking at certain angles, and I fire the projectile will sometimes fly off in very strange directions. I'm thinking it's something to do with the code too, but if not does anyone know what the problem is? Thanks for taking time to read this and helping out.

:)

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
Best Answer

Answer by Berenger · Jan 22, 2013 at 09:48 AM

To play sounds on top of one another, I think you'll need an audiosource for each. You should Instantiate a gameobject with that audiosource end the right clip each time you shoot (make sure to delete them when they stopped playing, and don't forget that Destroy has a time parameter).

For the second part, from the doc : "Transforms direction from local space to world space". So change that line for :

    clone.velocity = transform.forward * 50; 


Comment
Add comment · 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

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

10 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

Related Questions

Audio Playing upon death 1 Answer

Clicking noise problem while combining 2 sounds in Unity 1 Answer

Unity3d Networking Bugs Not Sure. 0 Answers

Musical game mute and unmute trigger soundsource 1 Answer

Need help coding different footstep sounds on different surfaces - Beginner` 1 Answer


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