You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
1.1 KiB
42 lines
1.1 KiB
7 years ago
|
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);
|
||
|
}
|
||
|
|
||
|
|
||
|
[Serializable]
|
||
|
public class Vector3andSpace
|
||
|
{
|
||
|
public Vector3 value;
|
||
|
public Space space = Space.Self;
|
||
|
}
|
||
|
}
|
||
|
}
|