因此,我試圖使用代碼在鍵上來回擺動武器,但由於某些原因,沒有發生。我已經通過單獨運行測試了代碼的各個部分,並且我的所有語句都在這裏和那裏進行了一些更改。但我無法弄清楚如何將它們融合在一起,並讓它們全部運行。欣賞任何指針!我的腳本永遠不會運行我的if語句的內容,但我沒有得到任何錯誤
public float BackRotationsSpeed = 100f;
public float ForwardRotationSpeed = 300f;
// Use this for initialization // Original rotation cordinates of sword (-1.523,86.914,8.212)
void Start() {
// Rotation kan foregå på left right up down forward backwards
}
// Update is called once per frame
void Update() {
if (Input.GetKey (KeyCode.U) && transform.eulerAngles.z > 8.2 && transform.eulerAngles.z < 8.3) // Checks if sword is in its original location, and if it is swing backwards.
{
transform.Rotate (Vector3.forward, -BackRotationsSpeed * Time.deltaTime);
}
if (Input.GetKey (KeyCode.U) && transform.eulerAngles.z > 70 && transform.eulerAngles.z < 200) // Checks if sword has reached furthest back point before swining forward + triple the speed swinging forward for extra oomf!
{
transform.Rotate (Vector3.forward, ForwardRotationSpeed * Time.deltaTime);
}
if(Input.GetKey (KeyCode.U) &&transform.eulerAngles.z>8.3 && transform.eulerAngles.z<70) // Checks if sword has reached furthest forward point in the forward swing, if it is reset the rotation to its origin and wait for next attack command
{
Vector3 temp = transform.rotation.eulerAngles;
temp.z = 8.21f;
transform.rotation = Quaternion.Euler(temp);
}
當你放置一個斷點,一步一步移動你的代碼不會進入任何if語句? –
當你的z角度較低時,你將會陷入僵局8.2。 –