Files
LowPolyRPG/Assets/Plugins/RaycastPro/_Demo/_Scripts/FreeTurn.cs

51 lines
1.3 KiB
C#
Raw Normal View History

2025-06-25 11:10:11 +01:00
using UnityEngine;
namespace Plugins.RaycastPro.Demo.Scripts
{
public class FreeTurn : MonoBehaviour
{
[SerializeField] private Vector3 moveTurn;
[SerializeField] private Vector3 rotateTurn;
[SerializeField] private Vector3 randomRotate;
[SerializeField] private Vector3 randomMove;
[SerializeField] private float periodTime;
private float timer;
private void Start()
{
randomMove += new Vector3(Random.value * randomMove.x, Random.value * randomMove.y,
Random.value * randomMove.z);
rotateTurn += new Vector3(Random.value * randomRotate.x, Random.value * randomRotate.y,
Random.value * randomRotate.z);
}
private void Update()
{
if (periodTime > 0)
{
if (timer >= periodTime)
{
Apply(1);
timer = 0;
}
else
{
timer += Time.deltaTime;
}
}
else
{
Apply(Time.deltaTime);
}
}
public void Apply(float delta)
{
transform.Rotate(rotateTurn * delta);
transform.Translate(moveTurn * delta);
}
}
}