How to activate a game object when multiple variables reach a certain value?

I want to make a game object (drag and drop in inspector) active when a date is reached and that date is made up of 3 variables so when all 3 of them are a certain value I would want it to activate a game object. The problem is that the variables are in another script along with all the other problems. This is highly flawed but I hope it shows the intent of what I was trying to do

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class Testevent1 : MonoBehaviour
{
    void Update()
    {
        if (ScriptDate2.day == 15 && ScriptDate2.month == 1 && ScriptDate2.year == 2000)
        {
            GameObject.SetActive(true);
        }
        else
        {
            GameObject.SetActive(false);
        }
    }
}

You’ll need a reference to the other script, something like this will find it if it exists in the scene:

public class Testevent1 : MonoBehaviour
{
    ScriptDate2 scriptDate2;

    void Start()
    {
        scriptDate2 = GameObject.FindObjectOfType<ScriptDate2>();
    }

    void Update()
    {
        // use your scriptDate2 script values here
    }
}
1 Like
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class Testevent1 : MonoBehaviour
{
    ScriptDate2 scriptDate2;

    void Start()
    {
        scriptDate2 = GameObject.FindObjectOfType<ScriptDate2>();
    }
    void Update()
    {
        if (ScriptDate2.day == 15 && ScriptDate2.month == 1 && ScriptDate2.year == 2000)
        {
            GameObject.SetActive(true);
        }
        else
        {
            GameObject.SetActive(false);
        }
    }
}

I put it in but I am getting errors. I think I am not supposed to use if and else for non-static objects or the other way around. Is there a simpler and working way to get it to turn on any object (drag and drop)? I don’t want the else to turn it off if the values aren’t met anyway. Also thanks for your reply

edit: the image I put in to show the errors didn’t embed for me so this is them in text:
Assets\Testevent1.cs(16,13): error CS0120: An object reference is required for the non-static field, method, or property ‘ScriptDate2.day’
Assets\Testevent1.cs(16,38): error CS0120: An object reference is required for the non-static field, method, or property ‘ScriptDate2.month’
Assets\Testevent1.cs(16,64): error CS0120: An object reference is required for the non-static field, method, or property ‘ScriptDate2.year’
Assets\Testevent1.cs(18,13): error CS0120: An object reference is required for the non-static field, method, or property ‘GameObject.SetActive(bool)’
Assets\Testevent1.cs(22,13): error CS0120: An object reference is required for the non-static field, method, or property ‘GameObject.SetActive(bool)’

No, you’re just not being careful is all. See these two you defined? Which one do you think is your field? Yes, it’s the one that starts with the lowercase. You’re using the type name in upper case and not your field.

Really, don’t name things like this because as you’ve just discovered, if you don’t understand the difference between a type and a field, you’re going to get confused.

“ScriptDate2.month” is NOT the same as “scriptDate2.month”

1 Like

Alright thanks that works