- Home /
How do I make an unusable and hidden button until certain conditions are met ?
So I have been trying to get a "requirement" be set up for a button in order for it be usable and to appear, I am using doubles, and have tried to set it up with references and more here is the code, if anyone can help me or answer that would be nice.
also the error I got was about references, to be specific and I quote "NullreferenceException: Object reference not set to an instance of an object prestigebuttonrequisite.Update () (at assets/scripts/prestigebuttonrequisite.cs24) (pointing to my script I believe?)" sorry for not stating this sooner, hopefully this information should help resolve it.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class prestigebuttonrequisite : MonoBehaviour
{
// things that had to be set up ahead of time
public GameObject Prestigescreenbutton;
public GameObject PrestigeRequisiteobjectsource;
public double coins;
public double prestige_coins;
// references
public Idle_script_2 Game_manager;
void Start()
{
Prestigescreenbutton.SetActive(false);
}
void Update()
{
Game_manager.coins = coins;
Game_manager.prestigecoins = prestige_coins;
if (Game_manager.coins < 1e+100)
{
Prestigescreenbutton.SetActive(true);
}
if (Game_manager.prestigecoins < 0)
{
Prestigescreenbutton.SetActive(true);
}
}
}
what @Link0n3 says.
Please add more details. Why doubles? what values do the variables coins and prestigecoins have? why set it active in Update
when coins/prestigecoins is smaller than zero or 1e+100?
@Link0n3 I just updated for the error logs, sorry about not revealing it sooner, as for you @Captain_Pineapple I needed numbers well beyond 1e+100 (especially since I want a progression that isn't additive for my game that would result in extremely high numbers.) approximately around 1e+308 at least floats do not go high enough for the number from what I have seen, though the public double that I set up for this script is to test for references which that also failed I was attempting to use it as troubleshooting. The set to update was also something that I had tried as a solution, though I am really just a beginner with no idea what the hell I am doing to be honest
Answer by Paum380 · Sep 14, 2021 at 04:53 PM
hello jester, i couldn't identify the problem, but from what i have in mind is, the script is attached to the same gameobject as the button, so you can might change the GameObject reference and just disable the button.
try this:
//change this reference to...
public GameObject Prestigescreenbutton;
//this.
public Button Prestigescreenbutton;
This did not quite fix it. Turns out the problem has something to do with references at the moment.
Your answer
Follow this Question
Related Questions
Duplicating Component with Some Scene References in Serialized Scriptable Object Class Reference 0 Answers
The referenced script (CameraContoller) on this Behaviour is missing! 1 Answer
How do I store a public reference to a GameObject/GameObject's Component? 1 Answer
When pressing the space bar, the Unity editor detects it as the "O" key, how can I solve this? 2 Answers