我制作了这款名为Jumpol的游戏,讲述的是你试图跳过尽可能多的障碍,收集尽可能多的硬币。硬币可以用来改变你的球,使你自己复活,这样你就可以在赛道上得到另一次机会。
我已经在iOS和安卓应用商店发布了这个游戏,一些用户报告说跳跃速度很慢。
我在我4岁的安卓上测试了这个游戏,它运行得很好,而且我还在一些iOS设备上测试了它,它也运行得很好。有什么方法可以使这段代码运行更顺畅吗?
游戏链接(如果你想测试的话)
float speed = 12; // Speed of player.
float thrust = 34; // Jump force.
float gravity = -6.18f; // Gravity force.
bool isGrounded = false; // If on ground or not.
private void Awake () {
Instance = this;
}
private void Start () {
rb = GetComponent<Rigidbody> ();
}
private void Update () {
if (Application.platform == RuntimePlatform.WindowsEditor) DesktopControls ();
if (Application.platform == RuntimePlatform.IPhonePlayer ||
Application.platform == RuntimePlatform.Android) MobileControls ();
}
private void FixedUpdate () {
if (GameManager.Instance.started) {
Gravity ();
Move ();
}
}
private void OnCollisionEnter (Collision collision) {
if (collision.gameObject.tag == "Obstacle") {
gameObject.SetActive (false);
}
if (collision.gameObject.tag == "Ground") {
isGrounded = true;
}
}
private void OnCollisionExit (Collision collision) {
if (collision.gameObject.tag == "Ground") {
isGrounded = false;
}
}
private void OnTriggerEnter (Collider other) {
if (other.gameObject.tag == "Collectable") {
other.gameObject.SetActive (false);
}
}
/// <summary>
/// Controls for mobile devices.
/// </summary>
private void MobileControls () {
for (int i = 0; i < Input.touchCount; ++i)
if (Input.touchCount > 0 && Input.GetTouch (i).phase == TouchPhase.Began) Jump ();
}
/// <summary>
/// Controls for desktops.
/// </summary>
private void DesktopControls () {
if (Input.GetMouseButtonDown (0)) Jump ();
}
/// <summary>
/// Makes player jump.
/// </summary>
private void Jump () {
if (isGrounded) {
rb.velocity += new Vector3 (0, thrust, 0);
}
}
/// <summary>
/// Adds gravity.
/// </summary>
private void Gravity () {
rb.velocity += new Vector3 (0, gravity, 0);
}
/// <summary>
/// Moves player.
/// </summary>
private void Move () {
rb.velocity = new Vector3 (rb.velocity.x, rb.velocity.y, speed);
}发布于 2018-04-07 06:49:34
这将是一个评论,但我还不能评论。
为什么你自己来设计重力呢?为什么不让RB来处理呢?它也有一个脚本可访问的值来改变重力。重力的方向总是-y。我想在引擎盖下它会运行得更顺畅。
https://codereview.stackexchange.com/questions/184813
复制相似问题