The question is answered, right answer was accepted
Disable a dropdown option.
So I'm making a weapon switching dropdown to change your weapon. And the thing is, I want the weapons to unlock on a specific level. The level is stored in my GameSettings class, I know how to access that, but the problem is, I can't get the item's index and disable the item.
My item's code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class item : MonoBehaviour {
public Text label;
public GameSettings settings;
private void Start()
{
if (settings.level >= 1 && label.text != "AK-47")
{
GetComponent<Toggle>().interactable = false;
} else
{
GetComponent<Toggle>().interactable = true;
}
if (settings.level >= 6 && label.text != "AK-47" || label.text != "M4")
{
GetComponent<Toggle>().interactable = false;
}
else
{
GetComponent<Toggle>().interactable = true;
}
if (settings.level >= 17 && label.text != "AK-47" || label.text != "M4" || label.text != "870 Shotgun")
{
GetComponent<Toggle>().interactable = false;
}
else
{
GetComponent<Toggle>().interactable = true;
}
if (settings.level >= 22)
{
GetComponent<Toggle>().interactable = true;
}
}
}
Answer by JacobPlaysGames · Oct 28, 2017 at 06:56 PM
Okay, I figured it out. Had to change start to update (not really required, but did it just in case), and I added to the start of the Start function settings = new GameSettings(); No need to answer this question.
Follow this Question
Related Questions
Hide/Disable a Dropdown 1 Answer
Disable a single Dropdown option. 2 Answers
How to make a UI Image appear/disappear? 2 Answers
Problem in disabling button and error in the statement 0 Answers
Strange issue with scriptable objects in the "Create" menu 0 Answers