public override void OnAwake() { manager = getMax.manager; player = getMax.player; startIndex = player.curCellIndex; maxMovement = getMax.maxMovement; FinalCell finalCell = player.final.GetComponent <FinalCell>(); finalIndex = finalCell.index; }
//传送方法,供传送道具使用 public IEnumerator Portal(bool needDice) { //等待玩家停止移动 needRotate = false; stopMove = true; contiueMove = true; GameManager.instant.pause = true; while (isMove) { yield return(null); } //获取剩余步数 int resetMove = GameManager.instant.resetMove; //播放缩小动画 animator.SetTrigger("StartProtal"); yield return(new WaitForSeconds(1f)); //获取除终点外,以玩家终点开始的26格的随机格子 Dictionary <int, GameObject> allCells = GameManager.instant.cellDic; List <GameObject> cells = new List <GameObject>(); int finalIndex = final.GetComponent <FinalCell>().index; for (int i = 0; i < 26; i++) { finalIndex = Utility.GetVaildIndex(finalIndex + 1, allCells.Count); cells.Add(allCells[finalIndex]); } GameObject cell; while (true) { //int random = 4; //for (int i = 0; i < cells.Count; i++) //{ // TriCell tri = cells[i].GetComponent<TriCell>(); // if (tri != null && tri.index == random) // { // random = i; // break; // } //} int random = UnityEngine.Random.Range(0, cells.Count); cell = cells[random]; FinalCell finalCell = cells[random].GetComponent <FinalCell>(); if (finalCell == null || finalCell.playerPlane != gameObject) { break; } } Cell cellScript = Utility.GetCellScriptByTag(cell); //传送,并修改朝向 transform.position = cell.transform.position; ChangeDirAfterPortal(cellScript); //修改玩家所在的ID curCellIndex = cellScript.index; //如果是三角格,需要修正位置 if (Utility.IsTypeOf <TriCell>(cellScript)) { //后一个为三角格,前一个为普通格,向前补0.5 //否则后补0.5 bool need = Utility.IsSpcTri(curCellIndex); if (need) { transform.position += transform.up * 0.5f; } else { transform.position -= transform.up * 0.5f; } } //播放放大动画 animator.SetTrigger("FinishProtal"); yield return(new WaitForSeconds(1f)); //继续移动 stopMove = false; GameManager.instant.pause = false; contiueMove = false; //传送后不需要再投骰子 if (!needDice) { isPortal = true; GameManager.instant.StartGameLoop(resetMove); } }