//Co-routine for moving units from one space to next, takes a parameter end to specify where to move to. protected virtual IEnumerator SmoothMovement(Vector3?dir = null) { //dir 이 null 이면 리턴 if (dir == null) { yield return(null); } while (true) { //print("AA : " + Vector3.Distance(transform.position, grid.GetCurrnetGrid(transform.position))); if (CheckForward(dir.Value)) { if (Vector3.Distance(transform.position, grid.GetCurrentGrid(transform.position)) > 0.1f) { transform.Translate(dir.Value * speed); } else { CheckForward(dir.Value); transform.position = grid.GetCurrentGrid(transform.position) + new Vector3(0.001f, 0, 0.001f); StopMove(); photonView.RPC("Calculate", RpcTarget.All, dir.Value); //Debug.Log("Did Hit"); } } else { //print("AA"); photonView.RPC("Calculate2", RpcTarget.All, dir.Value); //grid.GetSetBoolPlayerOcuupationPosition(transform.position, playerTeam, true); if (grid.CheckWallPosition(grid.GetPreviousGrid(transform.position, dir.Value)) == false) { photonView.RPC("Calculate3", RpcTarget.All, dir.Value); //print("AA : " + grid.CheckWallPosition(grid.GetPreviousGrid(transform.position, dir.Value))); //grid.GetSetBoolPlayerOcuupationPosition(grid.GetPreviousGrid(transform.position, dir.Value), playerTeam, false); } photonView.RPC("shareArraySync", RpcTarget.All); //dir 이 null 이 아니면 실행 transform.Translate(dir.Value * speed); //print("SmoothMovement"); } //나중에 최적화를 위해 위치 변경 //grid.GridShare(transform.position, "A"); yield return(null); } }
private void Start() { //grid 초기화 grid = ClientLibrary.Grid.instance; if (PhotonNetwork.IsMasterClient && photonView.IsMine) { Debug.Log("나마스터임"); photonView.RPC("ChangeColorA", RpcTarget.All); CountdownTimer.instance.playerA = true; } else if (photonView.IsMine) { photonView.RPC("ChangeColorB", RpcTarget.All); CountdownTimer.instance.playerB = true; } if (!photonView.IsMine) { return; } else { //smoothMovment null 초기화 smoothMovement = SmoothMovement(null); //Get a component reference to this object's BoxCollider2D boxCollider = GetComponent <BoxCollider>(); //currentGrid 초기화 currentGrid = grid.GetNearestPointOnGrid(transform.position); controller = GetComponent <CharacterController>(); //위치 초기화 transform.position = grid.GetCurrentGrid(transform.position) + new Vector3(0.001f, 0, 0.001f);//반올림 error 보간값 } }