public void updateAI(GameObject sa) { AI_Controller ac = sa.GetComponent <AI_Controller>(); makepath mp = pf.GetComponent <makepath>(); ac.fp = mp.arr; ac.gp = mp.ret_path; if (ac.currentsec != null) { cs = ac.currentsec; } ac.startsec = cs; ac.currentsec = cs; ac.pr = pr; ac.Start(); ac.ac = this.gameObject; ac.audsor = this.aud; }
public void createAI(int amount) { bool veryfirst = false; if (amount == 0) { veryfirst = true; amount++; } for (int i = 0; i < amount; i++) { //Used to be veryfirst now is every first if (veryfirst) { if (goodarr.Length < 25) { makepath mp = pf.GetComponent <makepath>(); cs = mp.end_section; } else { cs = goodarr[goodarr.Length - 25]; } //veryfirst = false; } else { if (i != 0) { int comp; sectionNumber = Random.Range(0, fullarr.Length); comp = int.Parse(pr.GetComponent <playersection>().col); while (comp == sectionNumber) { sectionNumber = Random.Range(0, fullarr.Length); } //Debug.Log(sectionNumber); cs = fullarr[sectionNumber]; } else { string comp = pr.GetComponent <playersection>().col; bool notfound = true; int b = 25; for (int z = goodarr.Length - 1; z >= 0; z--) { if (goodarr[z].name == comp && notfound) { notfound = false; } else if (notfound == false) { if (z != 0 && b == 0) { cs = goodarr[z]; b--; } else if (z == 0 && b > 0) { int comp2; sectionNumber = Random.Range(0, fullarr.Length); comp2 = int.Parse(pr.GetComponent <playersection>().col); while (comp2 == sectionNumber) { sectionNumber = Random.Range(0, fullarr.Length); } //Debug.Log(sectionNumber); cs = fullarr[sectionNumber]; } else { b--; } } } } } spawnedai = Instantiate(ai); aicount++; spawnedai.name = "AI: " + (aicount).ToString(); ailist.Add(spawnedai); updateAI(spawnedai); } }
// Start is called before the first frame update public void Start() { v = new Vector3(0, 5, 0); sections = mazemake.GetComponent <mazecreater>().full_section_list; Stack <Light> llist2 = pf.GetComponent <makepath>().llist; int j = llist2.Count; for (int i = 0; i < j; i++) { Destroy(llist2.Pop()); } pf.GetComponent <makepath>().llist = new Stack <Light>(); for (int i = 0; i < sections.Length; i++) { GameObject s = sections[i]; //Changes the bad spaces back to the good spaces //s.GetComponent<Renderer>().material = s.GetComponent<attributes>().good; s.GetComponent <attributes>().paths = 4; s.GetComponent <attributes>().visited = false; if (s.GetComponent <attributes>().topwall.GetComponent <wall_attributes>().outside != true) { if (s.GetComponent <attributes>().topwall.transform.position.y < 0) { s.GetComponent <attributes>().topwall.transform.position += v; } s.GetComponent <attributes>().topwall.GetComponent <wall_attributes>().movable = true; } else { s.GetComponent <attributes>().paths -= 1; } if (s.GetComponent <attributes>().rightwall.GetComponent <wall_attributes>().outside != true) { if (s.GetComponent <attributes>().rightwall.transform.position.y < 0) { s.GetComponent <attributes>().rightwall.transform.position += v; } s.GetComponent <attributes>().rightwall.GetComponent <wall_attributes>().movable = true; } else { s.GetComponent <attributes>().paths -= 1; } if (s.GetComponent <attributes>().bottomwall.GetComponent <wall_attributes>().outside != true) { if (s.GetComponent <attributes>().bottomwall.transform.position.y < 0) { s.GetComponent <attributes>().bottomwall.transform.position += v; } s.GetComponent <attributes>().bottomwall.GetComponent <wall_attributes>().movable = true; } else { s.GetComponent <attributes>().paths -= 1; } if (s.GetComponent <attributes>().leftwall.GetComponent <wall_attributes>().outside != true) { if (s.GetComponent <attributes>().leftwall.transform.position.y < 0) { s.GetComponent <attributes>().leftwall.transform.position += v; } s.GetComponent <attributes>().leftwall.GetComponent <wall_attributes>().movable = true; } else { s.GetComponent <attributes>().paths -= 1; } } //Put run mazecreater here Debug.Log("stop"); //zzzdebugmakepath zmp = pf.GetComponent<zzzdebugmakepath>(); //zmp.Start(); //zmp.enabled = true; //zmp.square = this.GetComponent<trap>().collided_object; //Fix the remake maze makepath mp = pf.GetComponent <makepath>(); Debug.Log("first : " + this.GetComponent <trap>().collided_object); Debug.Log("second : " + mp.end_section); Debug.Log("third : " + mp.arr); Debug.Log("fourth : " + mp.player); mp.astack = mp.pathAlgorithm(this.GetComponent <trap>().collided_object, mp.end_section, mp.arr, mp.player); mp.setFun(mp.player); //this.GetComponent<trap>().enabled = false; //this.GetComponent<trap>().Start(); this.GetComponent <resetwalls>().enabled = false; }