How to change sprite after several clicks?

Hello there!

I’m new in Unity and trying to create simple clicker which will change images due to the number of clicks.

I have created clicker script but I can’t understand how to change the image after several clicks.

Please see my code, it’s pretty simple but it estimate the clicks:

using UnityEngine;
using UnityEngine.UI;

public class Game : MonoBehaviour
{
    public Text scoreText;
    private int score;

    public void OnClick()
    {
        score++;
        scoreText.text = score + "$";
    }

}

I have created Resources directory and uploaded images inside. All the attempts to create such a logic was unsuccessful.

Now I need to figure out how to create new logic for changing images, here are the questions:

  1. Do I need to create new script to change images or this logic should be created in the current script?
  2. Do you have any examples of such logic?
  3. Is there any manuals which you would recommend me to read? It’s my first day in Unity and at the moment all the tools was googled, I have no experience :slight_smile:

Thank you in advance, may the force be with you, stay calm, beatuful and smell good.

CODE NOT TESTED

using UnityEngine;
using UnityEngine.UI;

public class Game : MonoBehaviour
{
    [SerializeField] private Text scoreText;
    [SerializeField] private Image upgradable;
    [SerializeField] private Upgrade[] upgrades;
    private int nextUpgradeIndex = 0;
    private int score;

    public void OnClick()
    {
        score++;
        scoreText.text = score + "$";

        // Make sure we haven't reached the last upgrade
        if(nextUpgradeIndex < upgrades.Length)
        {
            // Check if we've reached the required score to upgrade, if so, apply new sprite
            if(upgrades[nextUpgradeIndex].CanBeUnlocked(score))
            {
                upgrades[nextUpgradeIndex].Apply(upgradable);
                nextUpgradeIndex++;
            }
        }
    }
}

public class Upgrade
{
    [SerializeField] private int clickThreshold;
    [SerializeField] private Sprite sprite;

    public bool CanBeUnlocked(int clickCount)
    {
        return clickCount >= clickThreshold;
    }

    public void Apply(Image image)
    {
        image.sprite = sprite;
    }
}