- Home /
Unlocking Items with a Gacha
Hello! I am trying to set up a gacha for my dress up game. Clothing items are rendered on the doll by clicking a button. Buttons that are won via gacha are non intractable until they are won from the gacha however, I am not sure how to do this via scripting.
So far, I have been able to create a list where I can assign buttons in the inspector. I have also figured out how to return the items randomly in the list.
using System.Collections;
using System.Collections.Generic;
using UnityEngine.UI;
using UnityEngine;
public class GachaManager : MonoBehaviour
{
public Items[] items;
[System.Serializable]
public class Items
{
public string itemName;
public Button itemButton;
//...other properties
}
private void OnMouseDown()
{
int itemsIndex = Random.Range(0, items.Length);
Debug.Log("You have drawn a " + items[itemsIndex].itemName);
//instantiate item
}
}
However, I can not figure out how to make the returned button interactable. I tried using
items[itemsIndex].itemButton.interactable = true;
but it gives me a Null Reference Exception.
Is there anyway to make randomly selected buttons intractable? I'm very new to coding so, I'm not even sure what I should be looking for. Thank you!!
Your answer
Follow this Question
Related Questions
Moving buttons 1 Answer
Problems while setting up buttons on the GUI 0 Answers
Main Menu GUI Button - Animation? 1 Answer
GUI: Overlapping and Box size collision 1 Answer
Main menu help needed (C#) 2 Answers