言語: 日本語
  • C#
  • JS
  • Boo

スクリプト言語

お好みのスクリプト言語を選択すると、サンプルコードがその言語で表示されます。

AudioSource.pan

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Sumbission failed

For some reason your suggested change could not be submitted. Please try again in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Switch to Manual
public var pan: float;
public float pan;
public pan as float

Description

チャンネルのパン位置を設定する。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.

	// 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 ExampleClass : 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 ExampleClass(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)