# Item Switch System

## Item Switch Input Configuration

The Item Switch system is controlled by the JU Character Controller and JU Inventory, they use the **Player Character Inputs** Asset file to call the item switch functions.

Here you can configure how you want your game's item exchange functions to be called:

<div data-full-width="false"><figure><img src="/files/pPrH6DHr6HxBdWAQekq2" alt=""><figcaption></figcaption></figure></div>

## How to use Slot/Sequential Item Switching

Sequential Item switching is seen in many shooting games where you have a primary, secondary, tertiary weapon... it is possible to have this mechanic using the Sequential Item Switch system.

&#x20;The item switching sequence is set in the **Sequence Slot** in the **JU Inventory** script.&#x20;

You can drag and drop items into each slot to set the default sequence.

<div align="left"><figure><img src="/files/Uo1McxGf6HlhFv4F9R3A" alt=""><figcaption></figcaption></figure></div>

## How to use UI Slot to set Sequential Switch order

You can use UI Inventory Slots to set primary, secondary, tertiary weapons...

You can also configure the **Inventory Slot UI** to only accept certain tag types, for example only accept large weapons as primary weapons and small weapons as secondary weapons.

<div align="left"><figure><img src="/files/49FzCpU8x4Ib7SC68r77" alt=""><figcaption></figcaption></figure></div>

## UI Slot Item Switching

If you activate the highlighted option below, you will activate a panel with options to use in the Inventory Slots.

<figure><img src="/files/LIvyBEQXLh4taS0Q9E2m" alt=""><figcaption></figcaption></figure>

<div align="left"><figure><img src="/files/Jd2QzYvmquodyJj3Pi8Z" alt=""><figcaption></figcaption></figure></div>

## Item Switching by code

To swtich items with a code is simple, the example code below switches items with a timer.

{% code title="SwitchItemByScriptSample.cs" lineNumbers="true" %}

```csharp
using UnityEngine;
using JUTPS; // <-- Use JUTPS Lib
public class SwitchItemByScriptSample : MonoBehaviour
{
    public float SecondsToSwitchItem = 2;
    public JUCharacterController JUCharacter;
    void Start()
    {
        // >>> Call the function at the given time repeatedly 
        InvokeRepeating(nameof(SwitchToNextItem), SecondsToSwitchItem, SecondsToSwitchItem);
    }
    private void SwitchToNextItem()
    {
        // >>> Call Next Item Switch function by JUCharacterController
        JUCharacter.SwitchToNextItem();
    }
}
```

{% endcode %}

### Switching Methods:

<pre class="language-csharp" data-full-width="false"><code class="lang-csharp">
<strong>// >>> Call next item
</strong>JUCharacter.SwitchToNextItem();

// >>> Call previous item
JUCharacter.SwitchToPreviousItem();

// >>> Switch to specific item in right hand
JUCharacter.SwitchToItem(id: 2, RightHand: true);

// >>> Switch to sequential slot item
JUCharacter.SwitchToItemInSequentialSlot(JUTPS.InventorySystem.JUInventory.SequentialSlotsEnum.third);

</code></pre>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://julhiecio.gitbook.io/ju-tps-documentation/game-development/how-to-use-inventory-and-add-items/item-switch-system.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
