Example #1
0
 // Start is called before the first frame update
 void Start()
 {
     transform.position = ball_spawn_point.transform.position;
     players            = new List <GameObject>();
     players.AddRange(AgentHelper.FindGameObjectInChildWithTag(transform.parent, "Blue"));
     players.AddRange(AgentHelper.FindGameObjectInChildWithTag(transform.parent, "Red"));
     // blue_goal_pos = transform.parent.Find("Blue_goal").gameObject.transform.position;
     // red_goal_pos = transform.parent.Find("Red_goal").gameObject.transform.position;
 }
        // private AgentAgentHelper AgentHelper = new AgentAgentHelper();

        public override void Initialize()
        {
            Time.timeScale = 1;
            // Debug.Log(Thread.CurrentThread.ManagedThreadId);
            //Random.seed = Thread.CurrentThread.ManagedThreadId;
            team                 = this.gameObject.tag;
            initial_position     = this.transform.position;
            initial_rotation     = this.transform.rotation;
            parent               = this.transform.parent;
            ball                 = parent.Find("Soccer Ball").gameObject;
            m_BehaviorParameters = gameObject.GetComponent <BehaviorParameters>();
            car_controller       = GetComponent <CarController>();
            self_rBody           = GetComponent <Rigidbody>();
            ball_rBody           = ball.GetComponent <Rigidbody>();
            goalCheck            = ball.GetComponent <GoalCheck_1v1>();
            GameObject car_sphere = this.transform.Find("Sphere").gameObject;

            if (team == "Blue")
            {
                car_sphere.GetComponent <Renderer>().material.SetColor("_Color", Color.blue);
                own_goal   = parent.Find("Blue_goal").gameObject;
                other_goal = parent.Find("Red_goal").gameObject;
                friends    = new List <GameObject>();

                foreach (GameObject go in AgentHelper.FindGameObjectInChildWithTag(parent, team))
                {
                    if (go.Equals(this.gameObject)) // I do this to exclude itself (not sure if its a good idea yet)
                    {
                        continue;
                    }
                    friends.Add(go);
                }
                enemies = new List <GameObject>(AgentHelper.FindGameObjectInChildWithTag(parent, "Red"));
            }
            else if (team == "Red")
            {
                car_sphere.GetComponent <Renderer>().material.SetColor("_Color", Color.red);
                own_goal   = parent.Find("Red_goal").gameObject;
                other_goal = parent.Find("Blue_goal").gameObject;
                friends    = new List <GameObject>();
                foreach (GameObject go in AgentHelper.FindGameObjectInChildWithTag(parent, team))
                {
                    if (go.Equals(this.gameObject)) // I do this to exclude itself (not sure if its a good idea yet)
                    {
                        continue;
                    }
                    friends.Add(go);
                }
                enemies = new List <GameObject>(AgentHelper.FindGameObjectInChildWithTag(parent, "Blue"));
            }
        }