- Home /
Make this accept gameobjects not just lights
How do I make this o it accepts gameobjects like cubes or other objects right now its only accepting lights and I cant seem to find why?
Here is the code:
{
public List<GameObject> gameobjects = new List<GameObject>();
public string theTime = System.DateTime.Now.ToString("hh:mm:ss");
public string theDate = System.DateTime.Now.ToString("MM/dd/yyyy");
public string StartDate = "mm/dd/yyy";
public string StartTime = "hh:mm:ss";
public string EndDate = "mm/dd/yyy";
public string EndTime = "hh:mm:ss";
// Use this for initialization
void Start ()
{
}
// Update is called once per frame
void Update ()
{
theTime = System.DateTime.Now.ToString("hh:mm:ss");
theDate = System.DateTime.Now.ToString("MM/dd/yyyy");
if(theDate == (StartDate) && theTime == (StartTime))
{
foreach(GameObject gameobject in gameobjects)
{
gameobject.SetActiveRecursively(false);
}
}
if(theDate == (EndDate) && theTime == (EndTime))
{
foreach(GameObject gameobject in gameobjects)
{
gameobject.SetActiveRecursively(true);
}
}
}
Answer by Landern · Nov 27, 2012 at 07:19 PM
Change GameObject to Transform
{
public List<Transform> objects = new List<Transform>();
public string theTime = System.DateTime.Now.ToString("hh:mm:ss");
public string theDate = System.DateTime.Now.ToString("MM/dd/yyyy");
public string StartDate = "mm/dd/yyy";
public string StartTime = "hh:mm:ss";
public string EndDate = "mm/dd/yyy";
public string EndTime = "hh:mm:ss";
// Use this for initialization
void Start ()
{
}
// Update is called once per frame
void Update ()
{
theTime = System.DateTime.Now.ToString("hh:mm:ss");
theDate = System.DateTime.Now.ToString("MM/dd/yyyy");
if(theDate == (StartDate) && theTime == (StartTime))
{
foreach(Transform object in objects)
{
object.gameObject.SetActiveRecursively(false);
}
}
if(theDate == (EndDate) && theTime == (EndTime))
{
foreach(Transform object in objects)
{
object.gameObject.SetActiveRecursively(true);
}
}
}
If either of your questions are answered, please mark them as such
I am geting an error: error CS1061: Type `UnityEngine.Transform' does not contain a definition for `SetActiveRecursively' and no extension method `SetActiveRecursively' of type `UnityEngine.Transform' could be found (are you missing a using directive or an assembly reference?)
NV$$anonymous$$ computer glitched some how sorry about that deleted the script and remade it and it worked. Thanks so much for all your help. I will accept and up your answer on both questions.
well did you include the missing class definition that is clearly missing from your code example that i copied?
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
MonoDevelop stuck in solution 0 Answers
How can i get ONLY the childrens of a GameOnbject with GetComponentsInChildren method? 5 Answers
Convert to array. 1 Answer
Convert To Using Array 2 Answers