「Unity/3d/視点操作」の版間の差分
提供: 初心者エンジニアの簡易メモ
(→サンプル) |
(→サンプル) |
||
| (同じ利用者による、間の2版が非表示) | |||
| 行4: | 行4: | ||
呼び出し(UniRxだと) | 呼び出し(UniRxだと) | ||
<pre> | <pre> | ||
| − | + | Observable.EveryUpdate() | |
| − | .Where(_ => Input.GetMouseButton( | + | .Where(_ => Input.GetMouseButton(1)) |
.Subscribe(_ => { | .Subscribe(_ => { | ||
RotateCamera(); | RotateCamera(); | ||
| 行24: | 行24: | ||
参考:https://xr-hub.com/archives/6272 | 参考:https://xr-hub.com/archives/6272 | ||
| − | == | + | ==OSごとの左右クリックのとき== |
| − | Input.GetMouseButton(0) | + | windows |
| + | <pre> | ||
| + | if (Input.GetMouseButton(1)) {} // 右 | ||
| + | if (Input.GetMouseButton(0)) {} // 左 | ||
| + | </pre> | ||
| + | |||
| + | mac | ||
| + | <pre> | ||
| + | if (Input.GetMouseButton(1)) {} // 副クリック | ||
| + | if (Input.GetMouseButton(0)) {} // 通常クリック | ||
| + | </pre> | ||
2023年2月24日 (金) 21:14時点における最新版
サンプル
右クリックからのドラッグで、視点操作
呼び出し(UniRxだと)
Observable.EveryUpdate()
.Where(_ => Input.GetMouseButton(1))
.Subscribe(_ => {
RotateCamera();
})
.AddTo(gameObject);
rotateSpeed = 2f;
private void RotateCamera()
{
Vector3 angle = new Vector3(Input.GetAxis("Mouse X") * rotateSpeed,Input.GetAxis("Mouse Y") * rotateSpeed, 0);
player.transform.RotateAround(mainCamera.transform.position, Vector3.up, angle.x);
mainCamera.transform.RotateAround(mainCamera.transform.position, transform.right, angle.y);
}
参考:https://xr-hub.com/archives/6272
OSごとの左右クリックのとき
windows
if (Input.GetMouseButton(1)) {} // 右
if (Input.GetMouseButton(0)) {} // 左
mac
if (Input.GetMouseButton(1)) {} // 副クリック
if (Input.GetMouseButton(0)) {} // 通常クリック
