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