-
-
Save bzgeb/cc31200da65d6927aa02f5e626249fda to your computer and use it in GitHub Desktop.
Starter Assets Jump Test
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 UnityEngine; | |
namespace StarterAssets.Test | |
{ | |
public class JumpTest : MonoBehaviour | |
{ | |
[SerializeField] StarterAssetsInputs _input; | |
[SerializeField] float _runTime = 0.1667f; | |
[SerializeField] float _time = 1.1667f; | |
[SerializeField] bool _sprint; | |
float _startingHeight; | |
Vector3 _startingPosition; | |
public float JumpHeight; | |
public float JumpDistance; | |
IEnumerator Start() | |
{ | |
_input.sprint = _sprint; | |
float elapsed = 0; | |
_input.move = new Vector2(0f, 1f); | |
while (elapsed < _runTime) | |
{ | |
yield return null; | |
elapsed += Time.deltaTime; | |
} | |
elapsed = 0f; | |
_input.jump = true; | |
_startingHeight = transform.position.y; | |
_startingPosition = transform.position; | |
while (elapsed < _time) | |
{ | |
JumpHeight = Mathf.Max(transform.position.y - _startingHeight, JumpHeight); | |
yield return null; | |
elapsed += Time.deltaTime; | |
} | |
JumpDistance = (transform.position - _startingPosition).magnitude; | |
_input.move = new Vector2(0f, 0f); | |
Debug.Log($"Jump Height:{JumpHeight} Jump Distance:{JumpDistance}"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment