I want to change the image using joystick controls.I have two two button(Go and Previous).How can I change the image using joystick


2 Answers 2


You can change configure your game to receive input from joystick in the InputManager in Unity editor. Expand Mousex and MouseY (for instance) and configure it to use Joystick keys. You may map each axis to two buttons on a joystick, mouse, or keyboard keys. The name of the string can be used to get input value from this axis from a script like this:

value1 = Input.GetAxis("MouseX"); //this can be renamed "Go"
value2 = Input.GetAxis("MouseY"); //this can be renamed "Previous"

An axis has a value between -1 and 1.The neutral case is 0.

Once you have the input, you can cycle between two (or as many you want) images on an image component.

Image img;
Texture2D[] mySprites; //an array of sprites
else if(value2>0)

I hope this will do :)


Within your MonoBehaviour:

float delay = 1f;
bool enableInput = true;

void Update() {
    if(Input.GetAxis("Horizontal")  0) {
        enableInput = false;
        Invoke("EnableInput", delay); 

void EnableInput() {
    enableInput = true;

For some reason the code is not shown properly.

If you provide more detail for your questions you will get better answers. In case of Unity3D it may is helpfull which version you use and in what language (C#, Javascript) you are coding.

Showing some of your existing code is always useful.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .