Using volume buttons on Android in Unity3d

后端 未结 4 394
深忆病人
深忆病人 2021-01-25 21:28

I am attempting to use the volume buttons in a unity3d game on Android. Unfortunately I can\'t see anything pertaining to volume being mapped as a KeyCode, so it seems to me tha

4条回答
  •  情深已故
    2021-01-25 21:43

    You can build your app as an android studio/eclipse project and modify the UnityPlayerActivity (see: Extending the UnityPlayerActivity Java Code)

    Then you can use the volume keys as described in this SO answer: Android - Volume Buttons used in my application

    An example of comunication from activity to unity3d context:

    UnityPlayer.UnitySendMessage("TheNameOfYourGameObject", "PublicMethodInThatGameObject", "StringArgument");
    

    Note that there have been rumors of Samsung (not Google) not accepting an app to their stores if the button behaviour has changed.

    Also, it would be good UX, if the user will still be able to change the volume of your app.

提交回复
热议问题