This repository has been archived on 2025-04-11. You can view files and clone it, but cannot push or open issues or pull requests.
public-speaking-vr/Assets/Standard Assets/Utility/AutoMoveAndRotate.cs
2016-11-19 13:14:49 -06:00

51 lines
1.3 KiB
C#

using System;
using UnityEngine;
namespace UnityStandardAssets.Utility
{
public class AutoMoveAndRotate : 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 Update()
{
float deltaTime = Time.deltaTime;
if (ignoreTimescale)
{
deltaTime = (Time.realtimeSinceStartup - m_LastRealTime);
m_LastRealTime = Time.realtimeSinceStartup;
}
transform.Translate(moveUnitsPerSecond.value*deltaTime, moveUnitsPerSecond.space);
transform.Rotate(rotateDegreesPerSecond.value*deltaTime, moveUnitsPerSecond.space);
}
public void SetMoveSpeed(Vector3 speed)
{
moveUnitsPerSecond.value = speed;
}
public void SetRotateSpeed(Vector3 speed)
{
rotateDegreesPerSecond.value = speed;
}
[Serializable]
public class Vector3andSpace
{
public Vector3 value;
public Space space = Space.Self;
}
}
}