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 Soapies · Apr 17, 2012 at 07:00 AM · inputaudionot workinginput.getbutton

Using input.getbuttondown to play audio = NOT WORKING? :(

I'm having the hardest time figuring out what's wrong here. When I press mouse 0 (which I set as "Attack1" in Input) I want it to play my attack sound. I've given my character an audio source, and I've given him this script:


var sound : AudioClip;

function Update (){

 if(Input.GetButtonDown("Attack1")){
     audio.Play();
 }

}


I've also dragged the corresponding audio file to the target slot in the inspector.

I don't know why this isn't playing :( I've checked the sound to make sure it even played anything, and it does. All the names are correct and all the capitals are in the right spot.

I know very little about scripts but I've done a lot of research and from the looks of things, this ought to do it?

What am I missing?

Comment
Add comment · Show 1
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 gregzo · Apr 17, 2012 at 07:02 AM 0
Share

Did you add a AudioSource component to the object?

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Soapies · Apr 17, 2012 at 08:32 AM

I did. :(

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
avatar image
0

Answer by Soapies · Apr 17, 2012 at 08:32 AM

fafase! You are a genius. That worked... but why would that make any difference? :/

Thank you so much!

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 fafase · Apr 17, 2012 at 10:55 AM 0
Share

Weel simply put, an audio source means a speaker (opposed to audio listener, a microphone). But a speaker is nothing without a sound, that is the AudioClip. clip is the defaul variable of the AudioClip. In you case, you could have tried AudioSource.Play() and I guess it would have worked but it is no proper way (to me).

With audio.clip = sound; you tell the compiler that for the audio you want that sound. You can now even change it later on, if for instance, you want your guy to emit a different sound depending on its health.

var soundHealthy : AudioClip;

var soundDying :AudioClip;

function Start(){

audio.clip = soundHealthy;}

function Update(){

audio.Play();

if(dying)

audio.clip = soundDying; }

avatar image fafase · Apr 17, 2012 at 10:55 AM 0
Share

By the way please post replies as comment not as an answer.Also, you should mark it as answered.

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

6 People are following this question.

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

Related Questions

Play sound upon Input in Javascript 1 Answer

First button press don't always register after scene load. 0 Answers

Play Sound on Fire (C#) 2 Answers

Can't get my sound to work.. 1 Answer

Something doesnt move with my prefabs to new scene, breaking my horizontal controller. 0 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