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 TeleportSanwich · Mar 29, 2012 at 01:52 AM · soundgunautomatic

Automatic repeated sound

I'm making a Geometry Wars/Asteroids kind of top down shooter. I'm using raycasts as my bullets and I have a script that shoots the raycasts at an interval, simulating an automatic laser (see below.) Is there some way I could make a "laser blast" sound play at the same time that the raycast is shooting? I want to add sound to the laser, but don't know how to do it. Can someone please help?

P.S Here's the code I use for my laser

 var fireRate : float = 0.5;
 var Range : float = 1000;
 var Force : float = 75;
 private var nextFire : float = 0.0;
 
 function Update(){
     if(Input.GetButton("Fire1")&& Time.time > nextFire){
         nextFire=Time.time + fireRate;
         RayShoot();
     }
 }
 
 function RayShoot () {
     var Hit : RaycastHit;
     var DirectionRay =transform.TransformDirection(Vector3.forward);
     Debug.DrawRay(transform.position , DirectionRay * Range , Color.blue);
     if(Physics.Raycast(transform.position , DirectionRay , Hit, Range)){
         if(Hit.rigidbody){
             Hit.rigidbody.AddForceAtPosition(DirectionRay * Force , Hit.point);
         }
     }
 }
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
1

Answer by gregzo · Mar 29, 2012 at 02:10 PM

audio.PlayOneShot(yourCoolSoundEffect,volume);

Where yourCoolSoundEffect is an audioClip (simply drag and drop a wav file in your project window to import it as an AudioClip), and volume is a float between 0.0 and 1.0.

Read a bit on AudioClip and AudioSource in the docs to get a better grasp of what you're doing.

Serve fresh.

Enjoy!

Comment
Add comment · Show 5 · 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 TeleportSanwich · Apr 01, 2012 at 01:30 AM 0
Share

Thanks bro!

avatar image Vollmondum · Oct 03, 2012 at 03:58 AM 0
Share

And it says $$anonymous$$ Identifier "youCoolSoundEffect"...

avatar image AlucardJay · Oct 03, 2012 at 04:28 AM 1
Share

yourCoolSoundEffect is the variable name used for the AudioClip. Read : http://docs.unity3d.com/Documentation/ScriptReference/AudioSource.PlayOneShot.html

avatar image gregzo · Oct 03, 2012 at 05:48 AM 0
Share

alucardj, always so patient... I'm surprised you're not takng the time to explain what a variable and a type is.

avatar image Vollmondum · Oct 03, 2012 at 08:36 AM 0
Share

Extraterrestrials (non-human) thank you for detailed answer.

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

Hello there!! So when i hold LMB its continuously makes the gun noise but i want it so that there a 2 second delay in between each gun sound, how do i do this?? 1 Answer

How to add sound to gun shot script 4 Answers

Automatic Shooting Script 0 Answers

Machine gun sound — better to loop individual bullets or have a longer sample? 0 Answers

hey here wesley again sound for my gun 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