• 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 Pueken · Apr 02, 2017 at 09:57 AM · audiosoundaudiosource

Audio source playing different soundfiles

Hello guys,

I am having a rather wierd problem, i am trying to make a FPS in Unity right now and i stumbled over something strange while trying to implement an audiosource which is supposed to play when i shoot a weapon. I have my Player prefab which makes use of the standart Unity FPS Movement script which already contains some sounds (running, landing etc.) and those are working fine. As i said now i am trying to add another sound that gets played when i shoot. This sound is supposed to be played from a Shootingscript;

 public AudioSource gunsound;
 
 void Update()
     {
         if (Input.GetButtonDown("Fire1"))
         {
             gunsound.Stop();
             gunsound.Play();
             Debug.Log("Shoot!");

At this point there is this Script and the linked audio source with the gunsound in the player prefab. Now comes the weird part, when i test it out, using leftclick doesnt make the gunsound, but it repeats the last sound the Player prefab made, e.g. when i walk and make a sound, leftclicking plays that sound, when i land after jumping, leftclicking makes the landingsound etc. Right now i have no idea on what to do anymore.

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

0 Replies

· Add your reply
  • Sort: 

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

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

shake the mouth painting when the user speaks 0 Answers

Best way to play many audio clips at the same time? 0 Answers

Help with sound clips [C#] 0 Answers

Random, 3d sound. 1 Answer

Is there a way to limit the output volume on an audio mixer group? 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges