狗屎Minimax坏我代码
This commit is contained in:
@@ -1,6 +1,4 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine;
|
||||
|
||||
namespace SickscoreGames.ExampleScene
|
||||
{
|
||||
@@ -16,7 +14,7 @@ namespace SickscoreGames.ExampleScene
|
||||
|
||||
private Transform _transform;
|
||||
private Rigidbody _rigidbody;
|
||||
private bool isGrounded;
|
||||
private bool _isGrounded;
|
||||
#endregion
|
||||
|
||||
|
||||
@@ -36,14 +34,18 @@ namespace SickscoreGames.ExampleScene
|
||||
void FixedUpdate ()
|
||||
{
|
||||
// check if grounded
|
||||
if (isGrounded) {
|
||||
if (_isGrounded) {
|
||||
// directional input
|
||||
Vector3 targetVelocity = new Vector3 (Input.GetAxis ("Horizontal"), 0f, Input.GetAxis ("Vertical"));
|
||||
float moveSpeed = (Input.GetKey (KeyCode.LeftShift)) ? runSpeed : walkSpeed;
|
||||
Vector3 targetVelocity = new Vector3 (ExampleUniversalInput.GetAxis("Horizontal"), 0f, ExampleUniversalInput.GetAxis ("Vertical"));
|
||||
float moveSpeed = (ExampleUniversalInput.GetKey (KeyCode.LeftShift)) ? runSpeed : walkSpeed;
|
||||
targetVelocity = _transform.TransformDirection (targetVelocity) * moveSpeed;
|
||||
|
||||
// calculate velocity and max velocity change
|
||||
#if UNITY_6000_0_OR_NEWER
|
||||
Vector3 velocity = _rigidbody.linearVelocity;
|
||||
#else
|
||||
Vector3 velocity = _rigidbody.velocity;
|
||||
#endif
|
||||
Vector3 velocityChange = (targetVelocity - velocity);
|
||||
velocityChange.x = Mathf.Clamp (velocityChange.x, -8f, 8f);
|
||||
velocityChange.z = Mathf.Clamp (velocityChange.z, -8f, 8f);
|
||||
@@ -51,14 +53,20 @@ namespace SickscoreGames.ExampleScene
|
||||
_rigidbody.AddForce (velocityChange, ForceMode.VelocityChange);
|
||||
|
||||
// jump input
|
||||
if (Input.GetKeyDown (KeyCode.Space))
|
||||
if (ExampleUniversalInput.GetKeyDown(KeyCode.Space))
|
||||
{
|
||||
#if UNITY_6000_0_OR_NEWER
|
||||
_rigidbody.linearVelocity = new Vector3 (velocity.x, CalculateJumpVerticalSpeed (), velocity.z);
|
||||
#else
|
||||
_rigidbody.velocity = new Vector3 (velocity.x, CalculateJumpVerticalSpeed (), velocity.z);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
// apply force to rigidbody
|
||||
_rigidbody.AddForce (new Vector3 (0f, -gravity * _rigidbody.mass, 0f));
|
||||
|
||||
isGrounded = false;
|
||||
_isGrounded = false;
|
||||
}
|
||||
#endregion
|
||||
|
||||
@@ -66,7 +74,7 @@ namespace SickscoreGames.ExampleScene
|
||||
#region Utility Methods
|
||||
void OnCollisionStay ()
|
||||
{
|
||||
isGrounded = true;
|
||||
_isGrounded = true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user