如何让平台在 Unity 中再次旋转之前等待几秒钟?

时间:2021-04-12 16:20:28

标签: c# unity3d rotation

我目前正在以初学者的身份制作 2D 游戏。我已经添加了一个旋转平台来统一。现在我希望平台等待一定的秒数,当平台是直的,然后它再次转向之前,就像在 gif 上一样。这样您就可以在 unity 右侧轻松选择秒数。有人可以解释一下吗?

谢谢

GIF:NeonBeats Platforms

当前脚本:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Spinning_Platform : MonoBehaviour
{
    private float rotZ;
    public float RotationSpeed;
    public bool ClockwiseRotation;

    void Update()
    {
        if (ClockwiseRotation==false)
        {
            rotZ += Time.deltaTime * RotationSpeed;
        }
        else
        {
            rotZ += -Time.deltaTime * RotationSpeed;
        }

        transform.rotation = Quaternion.Euler(0, 0, rotZ);
    }
}

1 个答案:

答案 0 :(得分:0)

您可以检查时间和旋转的条件。

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Spinning_Platform : MonoBehaviour
{
    public float rotZ;
    public float RotationSpeed;
    public bool ClockwiseRotation;
    public float time = 1;

    void Update()
    {
        time -= Time.deltaTime;
        if (time <= 0)
        {
            rotZ += 10;
            transform.rotation = Quaternion.Euler(0, 0, rotZ);
            if (rotZ == 180)
            {
                rotZ = 0;
                time = 1;
            }
        }
    }
}
相关问题