[UNSOLVED] I am creating a multiplatform WebGL game. I am trying to use the new input system. I already have keyboard configured (and controller too). Now I am trying to implement touch. I already added a joystick for rotation from Joystick pack. Refer below image for the settings.
Here is some code (I don’t want to edit).
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
public class Movement : MonoBehaviour
{
[Header("Thrust")]
[SerializeField] InputAction thrust;
[SerializeField] float ThrustStrength;
[SerializeField] AudioClip ThrustSound;
[Header("Rotation")]
[SerializeField] InputAction Rotation;
[SerializeField] float RotationStrength;
[SerializeField] Joystick joystick;
Rigidbody rb;
AudioSource audioSource;
void Start(){
rb = GetComponent<Rigidbody>();
audioSource = GetComponent<AudioSource>();
}
void OnEnable()
{
thrust.Enable();
Rotation.Enable();
}
void OnDisable()
{
thrust.Disable();
Rotation.Disable();
}
void FixedUpdate()
{
ProcessThrust();
ProcessRotation();
}
private void ProcessThrust(){
if (thrust.IsPressed()){
rb.AddRelativeForce(Vector3.up * Time.fixedDeltaTime * ThrustStrength);
if (!audioSource.isPlaying){
Debug.Log("Playing engine sound");
audioSource.PlayOneShot(ThrustSound);
}
}
else{
if (audioSource.isPlaying){
Debug.Log("Stopping engine sound");
audioSource.Stop();
}
}
}
private void ProcessRotation(){
rb.freezeRotation = true;
float RotationInput = Rotation.ReadValue<float>();
transform.Rotate(0, 0,(joystick.Horizontal + RotationInput) * -1 * Time.fixedDeltaTime * RotationStrength);
rb.freezeRotation = false;
}
}
I want to limit touch (In thrust) to only one side of the screen (the right). I don’t want to edit the script. Is there a way I can achieve this?