Skip to content

Instantly share code, notes, and snippets.

@IshidaGames
Created June 22, 2019 09:25
Show Gist options
  • Save IshidaGames/839384511e04bfd6aae31da779d7a3ad to your computer and use it in GitHub Desktop.
Save IshidaGames/839384511e04bfd6aae31da779d7a3ad to your computer and use it in GitHub Desktop.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour
{
//移動スピード
[SerializeField] float speed = 2.5f;
//方向転換のスピード
[SerializeField] float angleSpeed = 200;
//上下移動のスピード
[SerializeField] float upSpeed = 0.5f;
void Update()
{
//左右どちらかのShift押した場合と離している場合
if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift))
{
speed = 10;
}
//左右どちらかのShift押した場合と離している場合
if (Input.GetKeyUp(KeyCode.LeftShift) || Input.GetKeyUp(KeyCode.RightShift))
{
speed = 2.5f;
}
//WSキー、↑↓キーで移動する
float z = Input.GetAxisRaw("Vertical") * Time.deltaTime * speed;
//前進の後退
//後退は前進の3分の1のスピードになる
if (z > 0)
{
transform.position += transform.forward * z;
}
else
{
transform.position += transform.forward * z / 3;
}
//向きをMain Cameと同じにする
this.transform.rotation = Camera.main.gameObject.transform.rotation;
//Eキーで上昇
if (Input.GetKey(KeyCode.E))
{
transform.position += transform.up * upSpeed;
}
//Qキーで下降
if (Input.GetKey(KeyCode.Q))
{
transform.position -= transform.up * upSpeed;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment