Skip to content

Instantly share code, notes, and snippets.

@ayutaz
Created December 24, 2019 17:36
Show Gist options
  • Save ayutaz/22c92f243a42a212720565b3896132b7 to your computer and use it in GitHub Desktop.
Save ayutaz/22c92f243a42a212720565b3896132b7 to your computer and use it in GitHub Desktop.
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraControll : MonoBehaviour {
    // wasdでカメラの上下左右移動
    // Rで初めの位置に戻る
    [SerializeField] private float cameraSpeed = 0.03f;
    // カメラ移動の速度
    [SerializeField] private float wheelSpeed = 1f;
    // マウスホイールの回転値を格納する変数
    private float scroll;
    void FixedUpdate()
    {
        // マウスホイールの回転値を変数 scroll に渡す
        scroll = Input.GetAxis("Mouse ScrollWheel");
 
        // カメラの前後移動処理
        //(カメラが向いている方向 forward に変数 scroll と speed を乗算して加算する)
        Camera.main.transform.position = new Vector3(transform.position.x,transform.position.y + scroll * wheelSpeed,transform.position.z);
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment