Search Unity

Help me make this code more manageable C# Audio for collisions

Discussion in 'Scripting' started by wightwhale, Dec 6, 2012.

  1. wightwhale

    wightwhale

    Joined:
    Jul 28, 2011
    Posts:
    397
    I'm just looking for any recomendations that would make this code better. If I go ahead in this manner is going to be a huge bit of code which I think is avoidable but the way to do this is beyond me right now. This going to grow out of control very quickly.
    Code (csharp):
    1.  
    2. public enum PhysicMaterialType
    3. {
    4. SoundFailure = 0,
    5. AsteroidBall,
    6. BalloonRubber
    7. }
    8. public void PlaySoundBasedOnCollision ( PhysicMaterialType phyMatA, PhysicMaterialType phyMatB )
    9. {
    10.  
    11.     switch ( phyMatA )
    12.     {
    13.         case PhysicMaterialType.AsteroidBall:
    14.             {
    15.                 CheckAsteroidBallCollision ( phyMatB );
    16.                 break;
    17.             }
    18.         case PhysicMaterialType.BalloonRubber:
    19.             {
    20.                 CheckBalloonRubberCollision ( phyMatB );
    21.                 break;
    22.             }
    23.    }
    24. }
    25. void CheckAsteroidBallCollision ( PhysicMaterial phyMatB )
    26. {
    27.  
    28.     switch ( phyMatB )
    29.     {
    30.         case PhysicMaterialType.AsteroidBall:
    31.             {
    32.                 //Play AsteroidAsteroidBallSound
    33.                 break;
    34.             }
    35.         case PhysicMaterialType.BalloonRubber:
    36.             {
    37.                 break;
    38.             }
    39.    }
    40. }
    41.