Search Unity

Touch controls Emulating Keystroke

Discussion in 'Android' started by TSSTUDIOS, Jun 10, 2013.

  1. TSSTUDIOS

    TSSTUDIOS

    Joined:
    Jun 10, 2013
    Posts:
    15
    Is it possible lets say

    The character controlers have basic setup WASD for movement and Space for jump

    Im trying to figure out a way to make it so

    Lets say i got a GUI that is intended for my character jump in game
    can i assign so that when GUI texture is pressed it emulates a keystore in this case SPACE
     
  2. shaderbytes

    shaderbytes

    Joined:
    Nov 11, 2010
    Posts:
    900
    Yes it is possible and there are many ways to do it. I use compiler/preprocessor directives to add the input controller needed for different platforms in my game.

    eg :

    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class InputManager : MonoBehaviour {
    5.    
    6.    
    7.     public static InputControllerBase inputController;
    8.    
    9.    
    10.    
    11.     void OnEnable () {
    12.        
    13.         #if UNITY_STANDALONE_OSX || UNITY_STANDALONE_WIN || UNITY_WEBPLAYER || UNITY_FLASH         
    14.             inputController = gameObject.AddComponent<MouseKeyboardInput>();           
    15.         #endif
    16.        
    17.         #if UNITY_IOS || UNITY_ANDROID         
    18.             inputController = gameObject.AddComponent<TouchInput>();
    19.         #endif
    20.        
    21.         ProcessManager.processItems.Add(inputController);
    22.    
    23.     }
    24.    
    25.    
    26. }
     
  3. SethPDA

    SethPDA

    Joined:
    Mar 23, 2012
    Posts:
    8
    Thanks shaderbytes!
    How to specify the button we want to be pressed using your piece of code? I would need the right arrow key to be pressed when I press on a GUI texture.
    Please help