void Move(string unit) //unit movement { selectedobj = GameObject.Find(unit).GetComponent <UnitInfo>(); // get address of selected object int sox = selectedobj.x; // current x position of selected object int soy = selectedobj.y; // current y position of selected object for (int i = 0; i < selectedobj.posx.Length; i++) { for (int j = 0; j < selectedobj.posy.Length; j++) { int spx = selectedobj.posx[i]; // get x distance of selected object int spy = selectedobj.posy[j]; // get y distance of selected object if (spx + sox >= 0 && spx + sox <= 4 && spy + soy >= 0 && spy + soy <= 4) { string tile = selectedobj.Findtile(spx + sox, spy + soy); settile = GameObject.Find(tile).GetComponent <TileInfo>(); // get address of tile //GameObject Pointer = Instantiate(CanMove, new Vector2(settile.pos.x, settile.pos.y), Quaternion.identity); } } } }