_xiaofang/xiaofang/Assets/Obi/Samples/Common/SampleResources/Scripts/MoveAndRotate.cs
杨号敬 bcc74f0465 add
2024-12-18 02:18:45 +08:00

40 lines
1.1 KiB
C#

using System;
using UnityEngine;
namespace Obi
{
public class MoveAndRotate : MonoBehaviour
{
public Vector3andSpace moveUnitsPerSecond;
public Vector3andSpace rotateDegreesPerSecond;
public bool ignoreTimescale;
private float m_LastRealTime;
private void Start()
{
m_LastRealTime = Time.realtimeSinceStartup;
}
// Update is called once per frame
private void FixedUpdate()
{
float deltaTime = Time.fixedDeltaTime;
if (ignoreTimescale)
{
deltaTime = (Time.realtimeSinceStartup - m_LastRealTime);
m_LastRealTime = Time.realtimeSinceStartup;
}
transform.Translate(moveUnitsPerSecond.value*deltaTime, moveUnitsPerSecond.space);
transform.Rotate(rotateDegreesPerSecond.value*deltaTime, rotateDegreesPerSecond.space);
}
[Serializable]
public class Vector3andSpace
{
public Vector3 value;
public Space space = Space.Self;
}
}
}