0
\$\begingroup\$

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

\$\endgroup\$

2 Answers 2

1
\$\begingroup\$

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
if(value1>0)
   i++;
else if(value2>0)
   i--;
img.sprite=mySprites[i];

I hope this will do :)

\$\endgroup\$
0
\$\begingroup\$

Within your MonoBehaviour:



float delay = 1f;
bool enableInput = true;

void Update() {
    if(Input.GetAxis("Horizontal")  0) {
        ShowNextPicture();
        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.

\$\endgroup\$

You must log in to answer this question.

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