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