Sets a channels pan position linearly. Only works for 2D clips.
// Switches sound from left to right everytime the user presses space @script RequireComponent(AudioSource) var panOnLeft = false; function Start() { 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; [RequireComponent(typeof(AudioSource))] public class Example : MonoBehaviour { public bool panOnLeft = false; void Start() { audio.pan = 1; } void Update() { if (Input.GetKeyDown(KeyCode.Space)) if (panOnLeft) { panOnLeft = false; audio.pan = 1; } else { panOnLeft = true; audio.pan = -1; } } }
import UnityEngine import System.Collections [RequireComponent(typeof(AudioSource))] public class Example(MonoBehaviour): public panOnLeft as bool = false def Start() as void: audio.pan = 1 def Update() as void: if Input.GetKeyDown(KeyCode.Space): if panOnLeft: panOnLeft = false audio.pan = 1 else: panOnLeft = true audio.pan = (-1)