【发布时间】:2021-07-26 20:53:34
【问题描述】:
我目前正在以初学者的身份制作 2D 游戏,有人为我制作了一个用于旋转平台的脚本,该脚本在特定秒数后停止。但它有错误的质地。它总是颠倒的,即使它转过一次。就像在屏幕截图上一样。除此之外,关于平台的两件事不再适用于他制作的脚本。旋转速度和顺时针旋转。我将把两个不同的脚本放在屏幕截图下方。我希望你能理解这一点,如果你有任何问题,请随时提出。
谢谢!
之前的脚本:
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);
}
}
脚本之后:
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;
}
}
}
}
【问题讨论】: