【问题标题】:How can I make a platform wait a few seconds before spinning again in Unity?如何让平台在 Unity 中再次旋转之前等待几秒钟?
【发布时间】:2021-07-07 17:56:43
【问题描述】:

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

谢谢

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);
    }
}

【问题讨论】:

    标签: c# unity3d rotation


    【解决方案1】:

    您可以检查时间条件和轮换情况。

    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;
                }
            }
        }
    }
    

    【讨论】:

    • 不工作。它说命名空间不能直接包含字段或方法等成员
    • 现在可以旋转了,但是纹理有些错误。平台纹理在转动一次时仍然是颠倒的。旋转速度和顺时针旋转也不能正常工作。
    • 您能否详细说明您想要达到的目标?旋转与 GIF 相同。
    • 是的,没错,但问题是 RotationSpeed 和 ClockwiseRotation 这两个变量不再适用于该脚本。正如我所说,纹理有些错误,也许你知道,它可能是什么。
    猜你喜欢
    • 1970-01-01
    • 2017-07-20
    • 2014-12-04
    • 1970-01-01
    • 2012-10-03
    • 1970-01-01
    • 2022-06-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多