57 lines
1.2 KiB
C#
57 lines
1.2 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class ShipMoveSides : MonoBehaviour
|
|
{
|
|
[SerializeField]
|
|
private float _radius;
|
|
[SerializeField]
|
|
[Range(-1,1)]
|
|
private float _value;
|
|
[SerializeField]
|
|
private float _speed;
|
|
[SerializeField]
|
|
private float _rollAngle = 45;
|
|
[SerializeField]
|
|
private bool _isEnable = true;
|
|
|
|
public float Radius => _radius;
|
|
|
|
private void Update()
|
|
{
|
|
if (!_isEnable)
|
|
ResetInput();
|
|
|
|
ApplyMovement();
|
|
}
|
|
|
|
public void ToggleInput(bool value)
|
|
{
|
|
_isEnable = value;
|
|
}
|
|
|
|
private void ResetInput()
|
|
{
|
|
_value = Mathf.Lerp(_value, 0, Time.deltaTime);
|
|
}
|
|
|
|
public void UpdateInput(float val)
|
|
{
|
|
if (!_isEnable)
|
|
return;
|
|
|
|
_value = -val;
|
|
}
|
|
|
|
|
|
private void ApplyMovement()
|
|
{
|
|
var newPos = transform.localPosition + _value * Vector3.right;
|
|
newPos.x = Mathf.Clamp(newPos.x, -_radius, _radius);
|
|
|
|
transform.localPosition = Vector3.Lerp(transform.localPosition, newPos, Time.deltaTime * _speed);
|
|
transform.localRotation = Quaternion.Euler(new Vector3(0, 0, _value * -_rollAngle));
|
|
}
|
|
}
|