Search Unity

Split screen audio system

Discussion in 'Scripting' started by raycosantana, Dec 23, 2014.

  1. raycosantana

    raycosantana

    Joined:
    Dec 23, 2012
    Posts:
    319
    Im making a split screen multiplayer game, like you all know you cant have more than one listener on Unity, so I had this idea of taking the viewport position to screen coordinates and then add those to the audio listener position. It kind of works but there are several problems, its really really slow, the game is for console and this really drops down the fame rate a lot, and also im pretty sure there are better and cleaner ways of doing this.

    Please help me make this better:

    "AudioMan" is the object containing the Audio Listener

    Code (CSharp):
    1. foreach (Camera Cam in Cameras){
    2.             Vector3 ViewPortPos = Cam.WorldToViewportPoint(gameObject.transform.position);
    3.             Vector3 ScreenPositon = Cam.ViewportToScreenPoint(ViewPortPos);
    4.             Vector3 SoundPostion = AudioMan.transform.position;
    5.             SoundPostion += new Vector3 (ScreenPositon.x*0.05f,0,ScreenPositon.y*0.05f);
    6.         AudioSource.PlayClipAtPoint(AudioManager.Instance.Explosion, SoundPostion);
    7.         }
    Thanks in advance.
     
  2. raycosantana

    raycosantana

    Joined:
    Dec 23, 2012
    Posts:
    319
    Any idea how can I make this more efficient?