public class PlayerMove : MonoBehaviour {
public float speed = 15.0f; public float jumpspeed = 0.8f; public float gravity = 20.0f; private Vector3 moveDirection = Vector3.zero; // Use this for initialization void Start () { } // Update is called once per frame void Update () { //プレイヤーの移動 CharacterController controller = GetComponent<CharacterController>(); if (controller.isGrounded) { moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical")); moveDirection = transform.TransformDirection(moveDirection); moveDirection *= speed; //高速移動 if (Input.GetButton("Boost")) { moveDirection.x *= 1.75f; moveDirection.z *= 1.75f; }
の様なコードでキャラに高速移動が可能な状態になっています。
if (Input.GetButton("Boost"))では左のシフトボタンを設定している状態で、高速移動時は左シフトを押しっぱなしにしていないとブースト機能が発動出来ない状態になっています。
bool型を使用し、一回押せば常にブースト状態で移動が可能で、もう一度押せばブースト機能が解除され、
通常の速度に戻る様にしたいのですが、上手くいきません。
下記に私なりにコードを記述したやつです。
エラーではなく思っている状態には程遠い状態になっていますので、何処をどの様に書き直し、書き加えたらいのか教えて頂けると幸いです。
public float speed = 15.0f; public float jumpspeed = 0.8f; public float gravity = 20.0f; private Vector3 moveDirection = Vector3.zero; bool Fast; // Use this for initialization void Start () { Fast = false; } // Update is called once per frame void Update () { //プレイヤーの移動 CharacterController controller = GetComponent<CharacterController>(); if (controller.isGrounded) { moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical")); moveDirection = transform.TransformDirection(moveDirection); moveDirection *= speed; //高速移動 if (Input.GetButton("Boost")) { Fast = true; moveDirection.x *= 1.75f; moveDirection.z *= 1.75f; } else { Fast = false; moveDirection.x /= 1.75f; moveDirection.z /= 1.75f; }
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。