Girl_Number_4
New member
- Joined
- Nov 27, 2022
- Messages
- 1
- Programming Experience
- Beginner
Hey people I'm trying to make a sort of inventory system for my game when the player presses e they basically add a sprite to a list. My issue is I want to use the Q button to cycle through the items in the list but I have no idea how to go about getting the next element in the list here is my code so far.
C#:
using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.UI;
public class HarvestPlant : MonoBehaviour
{
public bool isInHarvestRange;
public Image image;
public Sprite harvestedSprite;
public List<Sprite> sprites = new List<Sprite>();
public Sprite selectedSprite;
public void HarvestPlantFunction()
{
sprites.Add(harvestedSprite);
}
private void Update()
{
image.sprite = selectedSprite;
if (Input.GetKey(KeyCode.Q))
{
Debug.Log("Q pressed");
selectedSprite = sprites[1];
// so basically the idea is that everytime you press q selected Sprite will go up in the elements by 1 value but if it's at max value return to the lowest value
}
}
}
Last edited by a moderator: