remanaged drag input and platform movement
This commit is contained in:
@@ -1,16 +1,16 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine;
|
||||
using VContainer;
|
||||
|
||||
public class PlatformManager : MonoBehaviour,IPlatformManager
|
||||
{
|
||||
[Inject] private IPool pool;
|
||||
[Inject] private IInputReader inputReader;
|
||||
|
||||
private float yPos = 0f;
|
||||
|
||||
public float rotSpeed = 5f;
|
||||
[SerializeField] private float inputScale = 360f;
|
||||
float rotAmount = 0;
|
||||
|
||||
private float targetRotAmount;
|
||||
private float smoothRotAmount;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
@@ -26,22 +26,23 @@ public class PlatformManager : MonoBehaviour,IPlatformManager
|
||||
{
|
||||
inputReader.OnDragValueChanged -= HandleDrag;
|
||||
}
|
||||
|
||||
private void LateUpdate()
|
||||
{
|
||||
#if UNITY_EDITOR || UNITY_STANDALONE
|
||||
if (!inputReader.isMouseButtonPressed) return;
|
||||
#endif
|
||||
|
||||
smoothRotAmount = Mathf.MoveTowards(
|
||||
smoothRotAmount,
|
||||
targetRotAmount,
|
||||
Time.deltaTime * 80f
|
||||
);
|
||||
|
||||
transform.Rotate(Vector3.up * smoothRotAmount, Space.World);
|
||||
|
||||
// Apply rotation
|
||||
transform.Rotate(Vector3.up * rotAmount, Space.World);
|
||||
}
|
||||
void ShowPlatforms()
|
||||
|
||||
private void HandleDrag(Vector2 drag)
|
||||
{
|
||||
rotAmount = -drag.x/Screen.width * inputScale;
|
||||
}
|
||||
|
||||
private void ShowPlatforms()
|
||||
{
|
||||
foreach (var platform in pool.All)
|
||||
{
|
||||
@@ -57,15 +58,6 @@ public class PlatformManager : MonoBehaviour,IPlatformManager
|
||||
platform.transform.position = new Vector3(0, yPos, 0);
|
||||
yPos--;
|
||||
}
|
||||
|
||||
private void HandleDrag(Vector2 drag)
|
||||
{
|
||||
float raw = drag.x / Screen.width;
|
||||
|
||||
targetRotAmount = -raw * rotSpeed * 180f;
|
||||
|
||||
targetRotAmount = Mathf.Clamp(targetRotAmount, -10f,10f);
|
||||
}
|
||||
}
|
||||
|
||||
public interface IPlatformManager
|
||||
|
||||
Reference in New Issue
Block a user