ユニティに関するヘルプフォーラムを見ると、私が見ていた構文が本当に時代遅れであることがわかりました(同じことがここにあります:Unity Doublejump in C#)。Unity2Dでのダブルジャンプ制限
は、ここで私が話していた記事です。たとえば http://answers.unity3d.com/questions/753238/restrict-number-of-double-jumps.html
、無効覚醒()で、私が使用しているユニティの現在のバージョンでは、それはrigidbody2D.fixedAngle = trueのことを言います。もはやサポートされなくなりました。プログラムしようとしていたgameObjectに制約を適用する必要がありました(x軸、y軸またはz軸はどの軸を使うべきですか)。いくつかの編集を行い、エラーメッセージを調べた後、私はrigidbody2D.velocityのすべてをGetComponent().velocityという更新された構文に変更することができました。
ここに私のコードです:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class NewBehaviourScript : MonoBehaviour {
public float speed = 6.0f;
//public float j
Transform groundCheck;
//private float overlapRadius = 0.2f;
public LayerMask whatisGround;
private bool grounded = false;
private bool jump = false;
public float jumpForce = 700f;
private bool doubleJump = false;
public int dJumpLimit = 5;
void Start()
{
groundCheck = transform.Find ("groundcheck");
PlayerPrefs.SetInt ("doublejumps", dJumpLimit);
}
void Update()
{
if (Input.GetKey(KeyCode.Space))
{
jump = true;
}
//perhaps put A and D here?
}
void FixedUpdate()
{
//to check if Mario is on the ground
//overlap collider replace Overlap Circle???
//overlap point??
//grounded = GetComponent<Rigidbody2D>().OverlapCollision(groundCheck.position, overlapRadius, whatisGround);
if (grounded)
doubleJump = false;
if (dJumpLimit < 1)
doubleJump = true;
bool canJump = (grounded || !doubleJump);
if (jump && canJump) {
GetComponent<Rigidbody2D>().velocity = new Vector2 (GetComponent<Rigidbody2D>().velocity.x, 0);
GetComponent<Rigidbody2D>().AddForce (new Vector2 (0, jumpForce));
if (!doubleJump && !grounded) {
doubleJump = true;
dJumpLimit--;
}
}
jump = false;
//code that will work with the limits?
//GetComponent<Rigidbody2D>().velocity = new Vector2(speed,GetComponent<Rigidbody2D>().velocity.y);
//this will make it stack?
//GetComponent<Rigidbody2D>().velocity = new Vector2(speed,GetComponent<Rigidbody2D>().velocity.x);
//GetComponent<Rigidbody2D>().velocity = new Vector2(speed,GetComponent<Rigidbody2D>().velocity.y);
}
}
良いところは、最後にコンパイルすることができたということです。しかし、私はまだ制約がどのように働くのかわかりません(x、y、z軸の動きに抵抗します)。ジャンプはまだキャップストーンを持たず、変数dJumpLimitはすべてのジャンプを止めていないようです!ブーリアンたちが成し遂げようとしていることを解読しようとするのに苦労しました。旧式のコードが何をしようとしていたのか、私が失敗したことを教えてください。それは私をたくさん助けてくれるだろう。助けてくれてありがとう!
マリオが地上にあるとき、プレイヤーはスペースを押すとマリオが接地されているか、単に二重跳びまだしていない場合、canJumpがtrueの場合、ジャンプは真となり、真です。あなたが地上のチェックをコメントアウトしたので、doubleJumpは常にあなたがいつもダブルジャンプできるという意味では間違いです。 –
ありがとう! –