AudioSource.pan Manual     Reference     Scripting  
Scripting > Runtime Classes > AudioSource
AudioSource.pan

var pan : float

Description

Sets a channels pan position linearly. Only works for 2D clips.

-1.0 to 1.0. -1.0 is full left. 0.0 is center. 1.0 is full right. Only sounds that are mono or stereo can be panned. Multichannel sounds (ie >2 channels) cannot be panned.

JavaScripts
// Switches sound from left to right everytime the user presses space

var panOnLeft = false;
audio.pan = 1;

function Update() {
if(Input.GetKeyDown(KeyCode.Space)) {
if(panOnLeft) {
panOnLeft = false;
audio.pan = 1;
} else {
panOnLeft = true;
audio.pan = -1;
}
}
}

using UnityEngine;
using System.Collections;

public class example : MonoBehaviour {
public bool panOnLeft = false;
void Update() {
if (Input.GetKeyDown(KeyCode.Space))
if (panOnLeft) {
panOnLeft = false;
audio.pan = 1;
} else {
panOnLeft = true;
audio.pan = -1;
}

}
void Awake() {
audio.pan = 1;
}
}

import UnityEngine
import System.Collections

class example(MonoBehaviour):

public panOnLeft as bool = false

def Update():
if Input.GetKeyDown(KeyCode.Space):
if panOnLeft:
panOnLeft = false
audio.pan = 1
else:
panOnLeft = true
audio.pan = (-1)

def Awake():
audio.pan = 1