Search Unity

Question PLS HELP CrossPlatformInputManager to GetKeyDown

Discussion in 'Scripting' started by latasever8, May 29, 2020.

  1. latasever8

    latasever8

    Joined:
    Jun 22, 2019
    Posts:
    16
    I need to port my pc game to android.
    I'm trying a code like this but its not working
    Code (CSharp):
    1.  
    2.         (CrossPlatformInputManager.GetButtonDown ("E")) = (Input.GetKeyDown (KeyCode.E));
    please help me
     
  2. latasever8

    latasever8

    Joined:
    Jun 22, 2019
    Posts:
    16
    Code (CSharp):
    1.  
    2.         if (CrossPlatformInputManager.GetButtonDown ("E")) {
    3.  
    4.             Input.GetKeyDown (KeyCode.E);
    5.  
    6.         }
    also it didnt work
     
  3. Antistone

    Antistone

    Joined:
    Feb 22, 2014
    Posts:
    2,836
    If you want to know whether you're getting "E" from either of two different input systems, you'd write something like

    Code (CSharp):
    1. if (CrossPlatformInputManager.GetButtonDown("E") || Input.GetKeyDown(KeyCode.E))
    2. {
    3.     // Do stuff
    4. }
     
    latasever8 likes this.
  4. latasever8

    latasever8

    Joined:
    Jun 22, 2019
    Posts:
    16

    actually I want to do this = when I press a button, it must act like I press E key
     
  5. Antistone

    Antistone

    Joined:
    Feb 22, 2014
    Posts:
    2,836
    Well, you certainly can't do that in anything like the way you're trying to do it (and probably not at all). Those aren't variables, they're functions; when you invoke one, it runs some code and returns an answer. You can't "set" their values (at least not directly).

    I haven't used CrossPlatformInputManager and it's not showing up in the Unity scripting API, so I'm not sure what it's capabilities are, but UnityEngine.Input doesn't have a way for you to override its values. CrossPlatformInputManager kinda sounds like it should probably already handle input from multiple platforms without you needing to do anything, so if you haven't already, you should definitely look into how that works and see if it already does everything you need by itself.

    But if you need to combine them--and if neither of their creators did a bunch of extra work specifically to allow you to do that--then you'll need to do it by changing how your code reacts to them, not by changing the inputs themselves. You can either go to every place that your code is testing one of them and make it also test the other, or you can write your own middle layer that combines both of them into one thing and then make all of your code go through your middle layer instead of talking to them directly.

    But changing one to match the other is probably not in the cards.
     
    latasever8 likes this.
  6. latasever8

    latasever8

    Joined:
    Jun 22, 2019
    Posts:
    16
    I understand thank you my friend :(