Created
April 11, 2021 13:43
-
-
Save tsumire-sunajima/25049d896dce439f9b2cfdd3f2c9f395 to your computer and use it in GitHub Desktop.
自機の挙動&ブーストの挙動
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class CubeMove : MonoBehaviour | |
{ | |
[SerializeField] | |
private float _baseMoveSpeed; | |
[SerializeField] | |
private AnimationCurve _curve; | |
private float _curveTime; | |
[SerializeField] | |
private float _curveTimeSpeed; | |
private bool _boostFlag; | |
// Start is called before the first frame update | |
void Start() | |
{ | |
} | |
// Update is called once per frame | |
void Update() | |
{ | |
float moveSpeed; | |
if(Input.GetKey(KeyCode.Space)) | |
{ | |
if (_boostFlag == false) | |
_boostFlag = true; | |
if (_curveTime != 0f) | |
_curveTime = 0f; | |
} | |
if(_boostFlag == true) | |
{ | |
_curveTime = _curveTime + _curveTimeSpeed; | |
if(_curveTime > 1.0) | |
{ | |
_curveTime = 0; | |
_boostFlag = false; | |
} | |
} | |
moveSpeed = _baseMoveSpeed + _curve.Evaluate(_curveTime); | |
if (Input.GetKey(KeyCode.W)) | |
{ | |
this.gameObject.transform.Translate(0f, 0f, 1f * moveSpeed); | |
} | |
if (Input.GetKey(KeyCode.A)) | |
{ | |
this.gameObject.transform.Translate(-1f * moveSpeed, 0f, 0f); | |
} | |
if (Input.GetKey(KeyCode.S)) | |
{ | |
this.gameObject.transform.Translate(0f, 0f, -1f * moveSpeed); | |
} | |
if (Input.GetKey(KeyCode.D)) | |
{ | |
this.gameObject.transform.Translate(1f * moveSpeed, 0f, 0f); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment