- Home /
automatic gamemanager script
I have made a capturing script with a boolean which changes to true when you capture a location, I want to make a manager that searches on the start for all gameobjects in the scene and makes a script on runtime with booleans for every instance that then can be used for anything like a percentage bar. I have the script for the capturing already finished, but I don't know how to start the manager... can someone help me with this?
Can you be a little clearer on what you're trying to do? I think I get the idea but I'm not going to write a script just to find out I'm wrong.
I am trying to make a manager that lists all the gameobjects that use the same script (or tag) which make them a capture point, this happens on startup of the level. it then makes a boolean for every "node". so I can do everything I want with those booleans, like a percentage bar, a warning system or a puzzle system.
Answer by Khada · Aug 22, 2012 at 09:39 AM
This script does what you want. Note that you should change all the 'GameObject' types to whatever your 'capture point' script/object type is.
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class Node
{
public Node(GameObject node, bool active)
{
kNode = node;
bActive = active;
}
public GameObject kNode = null;
public bool bActive = false;
}
public class Manager : MonoBehaviour
{
private List<Node> lNodes = new List<Node>();
// Use this for initialization
void Start ()
{
object[] aNodes = GameObject.FindObjectsOfType(typeof(GameObject));
for(int i = 0; i < aNodes.Length; ++i)
{
Node kNewNode = new Node((GameObject)aNodes[i], false);
lNodes.Add(kNewNode);
}
}
// Update is called once per frame
void Update ()
{
//example of iterating through all node and doing something
for(int i = 0; i < lNodes.Count; ++i)
{
if(lNodes[i].bActive)
{
lNodes[i].kNode.active = true;
}
}
}
}
Thanks $$anonymous$$hada, I am going to try this out and try to get it to work with a percentage bar.
Sure, let me know how it goes. Be sure to mark the question as answered if that does it. (Questions can be marked as answered by clicking the checkmark below the up/down vote buttons on any answer.)
yes it works for the most part, I only have really limited experience with C#. Thanks
Your answer
![](https://koobas.hobune.stream/wayback/20220613075951im_/https://answers.unity.com/themes/thub/images/avi.jpg)