Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
自機の挙動&ブーストの挙動
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