I don't understand why this doesn't work. The code only acts when I press "Horizontal" buttons.
Here's the code:
using UnityEngine;
using Flycer.Helpers;
namespace Flycer.Controllers
{
public class MovementNew : BaseController
{
#region ========== Variables ========
[SerializeField] [Tooltip("Forward moving speed")] [Range(0, 1f)] float _forSpeed = 0.5f;
[SerializeField] [Tooltip("Slide speed")] private float speedSlide = 10;
[SerializeField] [Tooltip("Max slide distance")] private float maxSlide = 4;
private Vector3 _curPos;
float slide = 0;
int i = 1;
#endregion ========== Variables ========
#region ========== Unity-time ========
private void Start()
{
base.On();
_curPos = transform.position;
}
private void Update()
{
if (!Enabled)
return;
if (Input.GetButton(Controls.Horizontal.ToString()))
Moving();
}
private void FixedUpdate()
{
_curPos += new Vector3(0, 0, _forSpeed);
}
#endregion ========== Unity-time ========
#region ========== Methods ========
void Moving()
{
slide = Input.GetAxis("Horizontal") * speedSlide;
_curPos.x += slide * Time.deltaTime;
_curPos.x = Mathf.Clamp(_curPos.x, -maxSlide, maxSlide);
transform.position = _curPos;
}
#endregion ========== Methods ========
}
}
It doesn't move in any condition whether it has a RigidBody or not.