Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only. On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live. Read our full announcement for more information and let us know if you have any questions.

Question Touch input problem

Discussion in 'Input System' started by catalinminzatmarcel, Jul 18, 2020.

  1. catalinminzatmarcel

    catalinminzatmarcel

    Joined:
    Jul 5, 2020
    Posts:
    1
    Hello! I started recently to learn unity, i made a web game and now i want to port it to android.
    The problem is that i dont know how to make a script for touch buttons. I want 4 simple buttons that move the player on a 3d terrain. I found this script https://assetstore.unity.com/packages/tools/input-management/simple-input-system-113033 , but still i was unable to do something, all 4 buttons are assigned to the input manager i think. I tried this, but its not working. For this level i dont need jump
    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. public class Sphere3 : MonoBehaviour
    4. {
    5.     public Color materialColor;
    6.     private Rigidbody m_rigidbody;
    7.  
    8.     public string horizontalAxis = "Horizontal";
    9.     public string verticalAxis = "Vertical";
    10.     public string jumpButton = "Jump";
    11.     public float speed;
    12.     private float inputHorizontal;
    13.     private float inputVertical;
    14.  
    15.  
    16.  
    17.     void Update()
    18.     {
    19.         inputHorizontal = SimpleInput.GetAxis(horizontalAxis);
    20.         inputVertical = SimpleInput.GetAxis(verticalAxis);
    21.  
    22.         Vector3 movement = new Vector3(inputHorizontal, 0.0f, inputVertical);
    23.  
    24.         m_rigidbody.AddForce(movement * speed);
    25.     }
    26.  
    27.     void FixedUpdate()
    28.     {
    29.         m_rigidbody.AddRelativeForce(new Vector3(0f, 0f, inputVertical) * 20f);
    30.     }
    31.  
    32.     void OnCollisionEnter(Collision collision)
    33.     {
    34.         if (collision.gameObject.CompareTag("Player"))
    35.             m_rigidbody.AddForce(collision.contacts[0].normal * 10f, ForceMode.Impulse);
    36.     }
    37.  
    38.     bool IsGrounded()
    39.     {
    40.         return Physics.Raycast(transform.position, Vector3.down, 1.75f);
    41.     }
    42. }
     

    Attached Files: