AudioSource.pan 平衡调整

var pan : float

Description描述

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

设置一个通道平衡调整线性位置,只工作于2D剪辑。

-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.

-1.0到1.0。-1.0是最左,0.0为中间,1.0是最右。只有声音是单声道或立体声可以被调整。多声道声音(大于2声道)不能被调整。

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;
	}
}
// 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;
		}
	}
}
最后修改:2011年4月5日 Tuesday 20:36

本脚本参考基于Unity 3.4.1f5

英文部分版权属©Unity公司所有,中文部分© Unity圣典 版权所有,未经许可,严禁转载 。