3
大家好!C#Unity字符跳躍真奇怪
我的UNITY 5代碼有問題。
我的角色可以跳躍,但他立即跳躍,速度太快。 它看起來很奇怪。
我將不勝感激您對我的代碼的反饋!
using UnityEngine;
using System.Collections;
public class Gravity : MonoBehaviour {
private float inputDirection;
private float VerticalSpeed;
private float gravity = -2f;
private float speedmultiplier = 5f;
private bool jump;
private Vector3 moveVector;
private CharacterController controller;
// Use this for initialization
void Start() {
controller = GetComponent<CharacterController>();
}
// Update is called once per frame
void Update() {
inputDirection = Input.GetAxis ("Horizontal");
moveVector = new Vector3 (inputDirection, VerticalSpeed, 0) * speedmultiplier;
controller.Move (moveVector * Time.deltaTime);
if (controller.isGrounded) {
VerticalSpeed = 0.0f;
jump = true;
} else {
VerticalSpeed = gravity;
jump = false;
}
if (Input.GetKey(KeyCode.X)) {
if(jump == true) {
VerticalSpeed += 25f;
}
}
}
}
謝謝!有效。 – SoulPixel