Search Unity

Audio how do i make diffrent sound for a ragdoll.

Discussion in 'Audio & Video' started by FedeStefan, Jan 26, 2020.

  1. FedeStefan

    FedeStefan

    Joined:
    Aug 15, 2018
    Posts:
    221
    hi yes im trying to make a script so when a ragdoll is in the scene it doesnt play death 1 always but death 2 at some point and death 3 and some point and death 4 at some point.

    how can i make this?
     
  2. knobblez

    knobblez

    Joined:
    Nov 26, 2017
    Posts:
    223
    Something like this(just call Die() at the same time you call Ragdoll()):

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class MyScript2 : MonoBehaviour {
    6.     public AudioClip death1;
    7.     public AudioClip death2;
    8.     public AudioClip death3;
    9.     public AudioClip death4;
    10.     public AudioSource audiosource;
    11.     private int deathSound;
    12.  
    13.     public void Die()
    14.     {
    15.         deathSound = Random.Range(1, 4);
    16.  
    17.         switch (deathSound)
    18.         {
    19.             case 1:
    20.                 {
    21.                     audiosource.PlayOneShot(death1);
    22.                     break;
    23.                 }
    24.             case 2:
    25.                 {
    26.                     audiosource.PlayOneShot(death2);
    27.                     break;
    28.                 }
    29.             case 3:
    30.                 {
    31.                     audiosource.PlayOneShot(death3);
    32.                     break;
    33.                 }
    34.             case 4:
    35.                 {
    36.                     audiosource.PlayOneShot(death4);
    37.                     break;
    38.                 }
    39.         }
    40.     }
    41. }
    42.  
     
    FedeStefan likes this.