# How to switch between items

## Item Switch Manager

This script controls the item switching system of the characters. It is possible to switch items by scrolling the mouse, sequentially with numbers on the alphanumeric keyboard, and by pressing the next/previous button.

<div align="left"><figure><img src="https://2945806600-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FCQMDx0LmgnRXXTklLhoh%2Fuploads%2FEadBQVOwuQnomdsq9KDt%2Fimage.png?alt=media&#x26;token=62a7316e-bd6f-4d16-ba94-9eba2d923417" alt=""><figcaption></figcaption></figure></div>

## How to use Sequential Item Switching

The item switching sequence is set in the **Sequence Slot** in the Inventory Component. You can drag and drop items into each slot and it will work normally.

<div align="left"><figure><img src="https://2945806600-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FCQMDx0LmgnRXXTklLhoh%2Fuploads%2F1qeaXhMZ2MjrA4nzn8qo%2Fimage.png?alt=media&#x26;token=1e97e681-e4e9-401e-9607-432d3c98ff67" alt=""><figcaption></figcaption></figure></div>

Or you can use Slots in the UI to set items in sequence:

<div align="left"><figure><img src="https://2945806600-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FCQMDx0LmgnRXXTklLhoh%2Fuploads%2F5O8jUEsPzl6Sw3ngUA6S%2Fimage.png?alt=media&#x26;token=54106920-c4f4-406b-aacd-54cb0ec94e02" alt=""><figcaption></figcaption></figure></div>

{% hint style="info" %}
It is important to note that unlike **Sequential Item Switching**, the item switching order is in the order of position in the Hierarchy(inside player bone hand) by default.
{% endhint %}



## Mobile Item Switching

Item Switching on mobile is done by [Mobile Rig](../how-to-create-a-mobile-game-with-ju-tps/mobile-inputs)&#x20;

<figure><img src="https://2945806600-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FCQMDx0LmgnRXXTklLhoh%2Fuploads%2Fb908irf8gI3xMpmR7zwC%2Fimage.png?alt=media&#x26;token=f95ca1a5-fc9e-433d-9400-ce6e8136ebe7" alt=""><figcaption></figcaption></figure>

## Inventory Item Switching

It is possible to equip items from the inventory by pressing the item slot and then the equip button.

<div align="left"><figure><img src="https://2945806600-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FCQMDx0LmgnRXXTklLhoh%2Fuploads%2FKKK9a6GYhtPzUYYcKVa6%2Fimage.png?alt=media&#x26;token=0fb5fb4b-72d3-4d4b-bf7c-fe0563cf2007" alt=""><figcaption></figcaption></figure></div>

## Switching by code

To switching an item for a code is simple, the below example code checks when you press the G key and switch items to the next one.

{% code lineNumbers="true" %}
```csharp
using UnityEngine;
public class SwitchOnPressGKeyExample : MonoBehaviour
{
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.G)) 
        {
            ItemSwitchManager.NextPlayerItem();
        }
    }
}
```
{% endcode %}



Some static methods you can use in code for item switching:

| Static Methods                                                                                                                       | Description                                                                     |
| ------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------- |
| SwitchCharacterItem(<mark style="color:blue;">JUCharacterController</mark> character, <mark style="color:blue;">int</mark> SwitchID) | Switch a JU Character item to a specific one in the list                        |
| SwitchPlayerItem(<mark style="color:blue;">int</mark> SwitchID)                                                                      | Switch player(JUCharacter with "Player" tag) item to a specific one in the list |
| NextPlayerItem()                                                                                                                     | Switch player(JUCharacter with "Player" tag) to next item in sequence.          |
| PreviousPlayerItem()                                                                                                                 | Switch player(JUCharacter with "Player" tag) to previous item in sequence.      |
