void OnTriggerEnter2D(Collider2D other) { if (other.gameObject.tag == "Box") { line = null; if (linePath != null) { linePath.Clear(); } line = other.transform.parent.gameObject; LineIndentificator lineList = line.transform.GetComponent <LineIndentificator> (); foreach (GameObject campo in lineList.path) { linePath.Add(campo); } } }
void OnTriggerEnter2D(Collider2D other) { if (other.tag == "Box") { if (walking && other.gameObject == field.gameObject) { other.gameObject.transform.GetComponent <ScriptField> ().preparaCampo = false; other.gameObject.transform.GetComponent <ScriptField> ().cancelaCampo = false; } bool testa = false; if (objeto.Count > 0) { objeto.Remove(objeto [0]); } if (testa == false) { objeto.Add(other.gameObject); } line = null; lineDown = null; lineUp = null; if (linePath != null) { linePath.Clear(); } if (walkLeft != null) { walkLeft.Clear(); } if (walkRight != null) { walkRight.Clear(); } if (lineDownPath != null) { lineDownPath.Clear(); } if (lineUpPath != null) { lineUpPath.Clear(); } if (walkUp != null) { walkUp.Clear(); } if (walkDown != null) { walkDown.Clear(); } line = other.transform.parent.gameObject; LineIndentificator lineList = line.transform.GetComponent <LineIndentificator>(); contta = lineList.path.Count; grid = line.gameObject.transform.parent.gameObject; /* * for (int i = 0; i < contta; i++) { * * linePath.Add (lineList.path [i]); * Debug.Log ("Percorre"); * * }*/ foreach (GameObject campo in lineList.path) { linePath.Add(campo); } backColor = new Vector4(linePath[0].transform.GetComponent <SpriteRenderer> ().color.r, linePath[0].transform.GetComponent <SpriteRenderer> ().color.g, linePath[0].transform.GetComponent <SpriteRenderer> ().color.b, linePath[0].transform.GetComponent <SpriteRenderer> ().color.a); switch (line.gameObject.transform.tag) { case "Linha1": lineUp = grid.transform.GetChild(1).gameObject; lineList = lineUp.transform.GetComponent <LineIndentificator> (); foreach (GameObject campo in lineList.path) { lineUpPath.Add(campo); } break; case "Linha2": lineDown = grid.transform.GetChild(0).gameObject; lineList = lineDown.transform.GetComponent <LineIndentificator> (); foreach (GameObject campo in lineList.path) { lineDownPath.Add(campo); } lineUp = grid.transform.GetChild(2).gameObject; lineList = lineUp.transform.GetComponent <LineIndentificator> (); foreach (GameObject campo in lineList.path) { lineUpPath.Add(campo); } break; case "Linha3": lineDown = grid.transform.GetChild(1).gameObject; lineList = lineDown.transform.GetComponent <LineIndentificator> (); foreach (GameObject campo in lineList.path) { lineDownPath.Add(campo); } lineUp = grid.transform.GetChild(3).gameObject; lineList = lineUp.transform.GetComponent <LineIndentificator> (); foreach (GameObject campo in lineList.path) { lineUpPath.Add(campo); } break; case "Linha4": lineDown = grid.transform.GetChild(2).gameObject; lineList = lineDown.transform.GetComponent <LineIndentificator> (); foreach (GameObject campo in lineList.path) { lineDownPath.Add(campo); } lineUp = grid.transform.GetChild(4).gameObject; lineList = lineUp.transform.GetComponent <LineIndentificator> (); foreach (GameObject campo in lineList.path) { lineUpPath.Add(campo); } break; case "Linha5": lineDown = grid.transform.GetChild(3).gameObject; lineList = lineDown.transform.GetComponent <LineIndentificator> (); foreach (GameObject campo in lineList.path) { lineDownPath.Add(campo); } break; } //FECHA SWITCH if (linePath.Count > 0) { for (int i = 0; i < linePath.Count; i++) { if (linePath [i].gameObject == objeto[0].gameObject) { if (i < 6) { walkRight.Add(linePath [i + 1].gameObject); } if (i > 0) { walkLeft.Add(linePath [i - 1].gameObject); } if (lineUpPath.Count > 0) { walkUp.Add(lineUpPath [i].gameObject); } if (lineDownPath.Count > 0) { walkDown.Add(lineDownPath [i].gameObject); } } } //FECHA FOR PERCORRE LISTA } foreach (GameObject fieldTest in walkUp) { fieldTest.gameObject.transform.GetComponent <ScriptField> ().onPath = true; //fieldTest.gameObject.transform.GetComponent<ScriptField> ().walkList.Add (transform.gameObject); } foreach (GameObject fieldTest in walkDown) { fieldTest.gameObject.transform.GetComponent <ScriptField> ().onPath = true; //fieldTest.gameObject.transform.GetComponent<ScriptField> ().walkList.Add (transform.gameObject); } foreach (GameObject fieldTest in walkLeft) { fieldTest.gameObject.transform.GetComponent <ScriptField> ().onPath = true; //fieldTest.gameObject.transform.GetComponent<ScriptField> ().walkList.Add (transform.gameObject); } foreach (GameObject fieldTest in walkRight) { fieldTest.gameObject.transform.GetComponent <ScriptField> ().onPath = true; //fieldTest.gameObject.transform.GetComponent<ScriptField> ().walkList.Add (transform.gameObject); } } //FECHA IF TAG } //ONTRIGGERENTER