- Home /
What is the best way to rewrite this script to a new InputSystem?
I decided to transfer the controls for the first-person game on android to the new InputSystem so that it is also available on the PC.
The stumbling block was the camera control - in the old system, the player could move the camera using an invisible panel on the right half of the screen (as in many FPS games).
Having trouble with the logic I have to create with the new input system without breaking the basic principle of how the camera controls work.
Here is the old script:
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
namespace PlayerBehaviour {
[RequireComponent(typeof(Image), typeof(RectTransform))]
public class CameraController : MonoBehaviour, IPointerDownHandler, IPointerUpHandler
{
public Vector2 RotationInputVector;
private bool _isDragging;
private void Update()
{
if (!_isDragging)
{
if (RotationInputVector != Vector2.zero)
{
RotationInputVector = Vector2.zero;
}
return;
}
foreach(Touch touch in Input.touches)
{
if (touch.phase == TouchPhase.Moved)
{
RotationInputVector.x = touch.deltaPosition.x;
RotationInputVector.y = touch.deltaPosition.y;
RotationInputVector.Normalize();
print(RotationInputVector.ToString());
}
else if (touch.phase == TouchPhase.Stationary)
{
RotationInputVector = Vector2.zero;
}
else if (touch.phase == TouchPhase.Ended)
{
RotationInputVector = Vector2.zero;
}
}
}
public void OnPointerDown(PointerEventData pointerEventData)
{
_isDragging = true;
}
public void OnPointerUp(PointerEventData pointerEventData)
{
_isDragging = false;
}
}
}
What is the best way to recreate this script using new InputSystem? I am new to it so i am stuck.
Comment