因此,我试图使用代码在键上来回摆动武器,但由于某些原因,没有发生。我已经通过单独运行测试了代码的各个部分,并且我的所有语句都在这里和那里进行了一些更改。但我无法弄清楚如何将它们融合在一起,并让它们全部运行。欣赏任何指针!我的脚本永远不会运行我的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。 –