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 Michael 12 · Mar 24, 2011 at 02:24 AM · audioplayerfpsrandom

Random FPS player Audio when player kills enemies

Is there way to have my FPS player play random audio clips whenever he kills and enemy? I was thinking something along the lines of the old Duke Nuke em games where sometimes he would say "That's Gotta Hurt"

or

"Id buy that for a Dollar"

etcetera

I was up late last night trying to figure out how something like that could be done but I'm still trying to wrap my head around this script stuff.

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

4 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Justin Warner · Mar 24, 2011 at 02:32 AM

Psuedo: Have an array of sounds... Or a List as people here like more.. W/e it's the same.

Get a random number in the array, each array spot has its own sound, so if you have 10, get a number between 1 and 10, and then play that when you kill someone... That make sense? So every kill, it gets a new number, which is a "new" sound...

Comment
Add comment · Show 3 · 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 MC HALO · Mar 24, 2011 at 06:40 AM 0
Share

that is a really good way :)

avatar image MC HALO · Mar 24, 2011 at 06:48 AM 0
Share

i know this is not my question but i would like to know how to call the arrays it the first time that i am using them. I just created a variable that is called RandomSound: AudioClip[];

now if i press Input key (S) what code will you put there to cycle trough the sounds ?

please help me as well lol thanks :)

and thank you $$anonymous$$ichael for the wonderful question :)

avatar image Justin Warner · Mar 24, 2011 at 12:43 PM 1
Share

Check out fierce waffle's answer, should work that way (deathSounds is = to RandomSounds in this case). Good luck both.

avatar image
0

Answer by DevonJS · Mar 24, 2011 at 08:22 AM

I would go with a random number generating system and have different voices for different numbers. I'm not exactly and expert when it comes to random generating but I got the idea from DOS. How in dos many games were random. but here's a little snip it of what

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 Fierce Waffle · Mar 24, 2011 at 09:15 AM

create an audio array. and pretend your when your player dies you call this function

function playDeathSound()
{
deathSounds.Play[Random.Range(0, deathSounds.length)]();
}

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 Michael 12 · Mar 25, 2011 at 02:36 PM 0
Share

This might work only if for when my player makes a kill, not gets killed. Y'know He shoots a Zombie alien and then says "That's gotta hurt!" $$anonymous$$aybe blasts another one with a rocket launcher and then says "Oooh, he made a mess!" And so on...

avatar image Fierce Waffle · Mar 26, 2011 at 04:54 AM 0
Share

With that basically make a script attached to the zombie and when it dies use GameObject.Find("whatever").GetComponent("whatever").play$$anonymous$$illSound();

avatar image
0

Answer by MC HALO · Apr 17, 2011 at 06:03 PM

Try this it works for me :

using UnityEngine; using System.Collections;

public class PlayMusic : MonoBehaviour {

 public AudioClip[] Tracks;

     // Update is called once per frame
     void OnGUI () {


         if (GUI.Button(new Rect(10,20,120,20),"Play Tracks")){
             audio.Stop();
             audio.PlayOneShot(Tracks[Random.Range(3,Tracks.Length)]);
             //audio.clip = Tracks[0];
                //    audio.Play();
         }

     }
 }

it was similar to Fierce Waffle answer mines basically plays when you click on the GUI button :)

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.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

How to make a random team chance? 1 Answer

How to add a subtitle to my game 2 Answers

Question about FPS Player Script 1 Answer

Audio for movement 1 Answer

Random footsteps 5 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