Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Touch input works on PC but not with Remote 5 (IOS)

Discussion in 'Scripting' started by Laven3, Apr 2, 2022.

  1. Laven3

    Laven3

    Joined:
    Feb 22, 2022
    Posts:
    1
    Hey! Im currently working on a mobile game (my first project).
    Today I worked on the touch input controll. Now my problem:
    On the PC with the mouse I can use the touch input like on a mobile device but with Unity remote 5 the touch input doesnt work. If I touch the screen nothing happened...

    Here is my code, did I used touch input wrong?

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class PlayerBehaviour : MonoBehaviour
    6. {
    7.    
    8.     private float _walkSpeed;
    9.     [SerializeField]
    10.     private float _rotationSpeed;
    11.     [SerializeField]
    12.     private float movingSpeed;
    13.     [SerializeField]
    14.     private float aimngSpeed;
    15.  
    16.     public FloatingJoystick variableJoystick;
    17.     public FloatingJoystick shootjoy;
    18.  
    19.     public bool hasWeapon;
    20.  
    21.  
    22.     Rigidbody my_rb;
    23.  
    24.  
    25.  
    26.     void Awake()
    27.     {
    28.         //get the reference to the Rigidbody
    29.         my_rb = GetComponent<Rigidbody>();
    30.         hasWeapon = false;
    31.     }
    32.  
    33.     void Update()
    34.     {
    35.         Movement();
    36.     }
    37.  
    38.     private void Movement() //Player movement and turn in movement direction
    39.     {
    40.  
    41.         if(Input.GetKey(KeyCode.Space) && hasWeapon)
    42.         {
    43.             _walkSpeed = aimngSpeed;
    44.         }
    45.         else
    46.         {
    47.             _walkSpeed = movingSpeed;
    48.         }
    49.  
    50.         float x_axis = variableJoystick.Horizontal;
    51.         float z_axis = variableJoystick.Vertical;
    52.  
    53.         float a_axis = shootjoy.Horizontal;
    54.         float c_axis = shootjoy.Vertical;
    55.  
    56.         Vector3 direction = new Vector3(x_axis, 0, z_axis).normalized;
    57.         Vector3 watching = new Vector3(a_axis, 0, c_axis).normalized;
    58.         Quaternion shootRotation = Quaternion.LookRotation(watching);
    59.  
    60.         //If watch input has some value
    61.         if (watching != Vector3.zero)
    62.         {
    63.             shootRotation = Quaternion.RotateTowards(transform.rotation, shootRotation, _rotationSpeed);
    64.             my_rb.MoveRotation(shootRotation);
    65.         }
    66.  
    67.         if (direction == Vector3.zero)
    68.             return;
    69.  
    70.         Quaternion targetRotation = Quaternion.LookRotation(direction);
    71.         targetRotation = Quaternion.RotateTowards(transform.rotation, targetRotation, _rotationSpeed);
    72.  
    73.         //controll the movement with the Rigidbody
    74.         my_rb.MovePosition(my_rb.position + direction * _walkSpeed * Time.deltaTime);
    75.  
    76.         //Check if the player should watch in walk direction or aiming direction
    77.         if (watching != Vector3.zero)
    78.         {
    79.             my_rb.MoveRotation(shootRotation);
    80.         }
    81.         else
    82.         {
    83.             my_rb.MoveRotation(targetRotation);
    84.         }
    85.  
    86.     }
    87. }
    88.  
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,520
    First just strip out EVERYTHING and make a script that just displays the length of
    Input.touches
    each frame and make sure touches are even getting into the remote.