x


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.

more ▼

asked Mar 24 '11 at 02:24 AM

Michael 12 gravatar image

Michael 12
132 86 98 106

(comments are locked)
10|3000 characters needed characters left

4 answers: sort voted first

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...

more ▼

answered Mar 24 '11 at 02:32 AM

Justin Warner gravatar image

Justin Warner
6.3k 19 27 65

that is a really good way :)

Mar 24 '11 at 06:40 AM MC HALO

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 Michael for the wonderful question :)

Mar 24 '11 at 06:48 AM MC HALO

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

Mar 24 '11 at 12:43 PM Justin Warner
(comments are locked)
10|3000 characters needed characters left

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 :)

more ▼

answered Apr 17 '11 at 06:03 PM

MC HALO gravatar image

MC HALO
878 74 94 111

(comments are locked)
10|3000 characters needed characters left

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

more ▼

answered Mar 24 '11 at 08:22 AM

DevonJS gravatar image

DevonJS
28 10 12 16

(comments are locked)
10|3000 characters needed characters left

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

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

answered Mar 24 '11 at 09:15 AM

Fierce Waffle gravatar image

Fierce Waffle
176 34 38 49

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!" Maybe blasts another one with a rocket launcher and then says "Oooh, he made a mess!" And so on...

Mar 25 '11 at 02:36 PM Michael 12

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

Mar 26 '11 at 04:54 AM Fierce Waffle
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

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

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1175
x1029
x808
x574

asked: Mar 24 '11 at 02:24 AM

Seen: 1340 times

Last Updated: Mar 24 '11 at 02:24 AM