public void RandomSpawn(int posX, int posZ) { if (objinfo[posX, posZ] == true) { Debug.Log("生成済み位置選択、return"); return; } //座標番号(spawnNumber)がtrueならここ以下を無視する objinfo[posX, posZ] = true; GameObject dice = Instantiate(SpawnDice, new Vector3(posX, -1.1f, -posZ), Quaternion.identity);//7*7だが原点0を考慮し6とする DiceControll diceControll = dice.GetComponent <DiceControll>(); diceControll.DiceSpawn(posX, posZ); Debug.Log(posX + "," + posZ);//生成時座標確認用 }
void ReceivePoint(GameObject chainFirstObj) { int srowCT = 0; Vector3 Raypos1 = transform.position; Vector3 Raypos2 = transform.position; Vector3 Raypos3 = transform.position; Vector3 Raypos4 = transform.position; Raypos1 += new Vector3(0, 0, 0.35f); Raypos2 += new Vector3(0, 0, -0.35f); Raypos3 += new Vector3(-0.35f, 0, 0); Raypos4 += new Vector3(0.35f, 0, 0); int wasdCheckFlag = 0; //上面数字更新判定 NumberCheck(); chainCheckFlag = true;//二度付け禁止フラグオン firstDiceControll = chainFirstObj.GetComponent <DiceControll>(); //四方上下にray + 数字更新 ここっから RaycastHit receiveChain;//連鎖時用 //四方 if (Physics.Raycast(Raypos1, Vector3.forward, out receiveChain, rayMaxDistance)) { if (receiveChain.collider.tag == "dice") { chainDiceControll = receiveChain.collider.gameObject.GetComponent <DiceControll>(); if (chainDiceControll.chainCheckFlag == true || upNumber != chainDiceControll.upNumber) { wasdCheckFlag += 1; } else if (upNumber == chainDiceControll.upNumber && chainDiceControll.chainCheckFlag == false) { firstDiceControll.chainCount += 1; chainDiceControll.ReceivePoint(chainFirstObj); // wasdCheckFlag = 0; srowCT += 1; } } } else { wasdCheckFlag += 1; } if (Physics.Raycast(Raypos2, Vector3.back, out receiveChain, rayMaxDistance)) { if (receiveChain.collider.tag == "dice") { chainDiceControll = receiveChain.collider.gameObject.GetComponent <DiceControll>(); if (chainDiceControll.chainCheckFlag == true || upNumber != chainDiceControll.upNumber) { wasdCheckFlag += 1; } else if (upNumber == chainDiceControll.upNumber && chainDiceControll.chainCheckFlag == false) { firstDiceControll.chainCount += 1; chainDiceControll.ReceivePoint(chainFirstObj); // wasdCheckFlag = 0; srowCT += 1; } } } else { wasdCheckFlag += 1; } if (Physics.Raycast(Raypos3, Vector3.left, out receiveChain, rayMaxDistance)) { if (receiveChain.collider.tag == "dice") { chainDiceControll = receiveChain.collider.gameObject.GetComponent <DiceControll>(); if (chainDiceControll.chainCheckFlag == true || upNumber != chainDiceControll.upNumber) { wasdCheckFlag += 1; } else if (upNumber == chainDiceControll.upNumber && chainDiceControll.chainCheckFlag == false) { firstDiceControll.chainCount += 1; chainDiceControll.ReceivePoint(chainFirstObj); // wasdCheckFlag = 0; srowCT += 1; } } } else { wasdCheckFlag += 1; } if (Physics.Raycast(Raypos4, Vector3.right, out receiveChain, rayMaxDistance)) { if (receiveChain.collider.tag == "dice") { chainDiceControll = receiveChain.collider.gameObject.GetComponent <DiceControll>(); if (chainDiceControll.chainCheckFlag == true || upNumber != chainDiceControll.upNumber) { wasdCheckFlag += 1; } else if (upNumber == chainDiceControll.upNumber && chainDiceControll.chainCheckFlag == false) { firstDiceControll.chainCount += 1; chainDiceControll.ReceivePoint(chainFirstObj); // wasdCheckFlag = 0; srowCT += 1; } } } else { wasdCheckFlag += 1; } if (srowCT > 1) { for (int i = 0; i < srowCT; i++) { if (firstDiceControll.branchFlag[i] != true) { firstDiceControll.branchFlag[i] = true; break; } } } if (firstDiceControll.chainCount >= firstDiceControll.upNumber) { banishFlag = true; firstDiceControll.Banish(); Banish(); } else if (firstDiceControll.chainCount < firstDiceControll.upNumber) { bool stackChecker = false; for (int i = 0; stackChecker == false; i++) { if (i >= 5) { Debug.Log("stackControllの範囲外、要調査" + i); stackChecker = true; break; } if (firstDiceControll.stackControll[i] == null) { firstDiceControll.stackControll[i] = this.gameObject.GetComponent <DiceControll>(); stackChecker = true; } } } if (wasdCheckFlag >= 4 && firstDiceControll.chainCount >= firstDiceControll.upNumber) { Debug.Log(" StackBanish()"); firstDiceControll.StackBanish();//条件修正予定 firstDiceControll.Banish(); firstDiceControll.banishFlag = true; //firstDiceControll.chainCheckFlag = false; //firstDiceControll.chainCount = 1; } if (wasdCheckFlag >= 4 && firstDiceControll.chainCount < firstDiceControll.upNumber)//連鎖数不足の場合chainncountを0に { for (int i = 0; i < branchFlag.Length; i++) { if (firstDiceControll.branchFlag[i] == true) { firstDiceControll.branchFlag[i] = true; Debug.Log("分岐消化"); return; } } chainCheckFlag = false; firstDiceControll.chainCheckFlag = false; firstDiceControll.chainCount = 1; for (int i = 0; i <= 4; i++) { if (firstDiceControll.stackControll[i] != null) { firstDiceControll.stackControll[i].chainCheckFlag = false; Debug.Log("分岐点クリーナー"); } } Debug.Log("投げた回数" + srowCT + "WASD" + wasdCheckFlag); } // if (wasdCheckFlag <= 3) { Debug.Log("投げた回数" + srowCT + "WASD" + wasdCheckFlag + "続行"); } // }//被チェイン時に作動
void WASD_Checker()//回転または移動終了時のチェインチェック、 { int mySrowCount = 0; //四方上下にray + 数字更新 RaycastHit chain;//連鎖時用 //上面数字更新判定 NumberCheck(); //stack内掃除 CleanStack(); //Raycast位置ずらし用vec3 Vector3 Raypos1 = transform.position; Vector3 Raypos2 = transform.position; Vector3 Raypos3 = transform.position; Vector3 Raypos4 = transform.position; Raypos1 += new Vector3(0, 0, 0.35f); Raypos2 += new Vector3(0, 0, -0.35f); Raypos3 += new Vector3(-0.35f, 0, 0); Raypos4 += new Vector3(0.35f, 0, 0); //四方 if (Physics.Raycast(Raypos1, Vector3.forward, out chain, rayMaxDistance)) { //debug.log(chain.collider.tag); if (chain.collider.tag == "dice") { chainDiceControll = chain.collider.gameObject.GetComponent <DiceControll>(); if (upNumber == chainDiceControll.upNumber && chainDiceControll.banishFlag == true) { banishFlag = true; Banish(); } else if (upNumber == chainDiceControll.upNumber) { chainCount += 1; chainDiceControll.ReceivePoint(IgnitionPoint()); } } } if (Physics.Raycast(Raypos2, Vector3.back, out chain, rayMaxDistance)) { //debug.log(chain.collider.tag); if (chain.collider.tag == "dice") { chainDiceControll = chain.collider.gameObject.GetComponent <DiceControll>(); if (upNumber == chainDiceControll.upNumber && chainDiceControll.banishFlag == true) { banishFlag = true; Banish(); } else if (upNumber == chainDiceControll.upNumber) { chainCount += 1; chainDiceControll.ReceivePoint(IgnitionPoint()); } } } if (Physics.Raycast(Raypos3, Vector3.left, out chain, rayMaxDistance)) { //debug.log(chain.collider.tag); if (chain.collider.tag == "dice") { chainDiceControll = chain.collider.gameObject.GetComponent <DiceControll>(); if (upNumber == chainDiceControll.upNumber && chainDiceControll.banishFlag == true) { banishFlag = true; Banish(); } else if (upNumber == chainDiceControll.upNumber) { chainCount += 1; chainDiceControll.ReceivePoint(IgnitionPoint()); } } } if (Physics.Raycast(Raypos4, Vector3.right, out chain, rayMaxDistance)) { //debug.log(chain.collider.tag); if (chain.collider.tag == "dice") { chainDiceControll = chain.collider.gameObject.GetComponent <DiceControll>(); if (upNumber == chainDiceControll.upNumber && chainDiceControll.banishFlag == true) { banishFlag = true; Banish(); } else if (upNumber == chainDiceControll.upNumber) { chainCount += 1; chainDiceControll.ReceivePoint(IgnitionPoint()); } } } }
void Update() { RaycastHit dice; //連鎖時用 if (!iTweenMoving && Input.GetKey("up") && posY >= 1) //↑ { iTween.RotateTo(this.gameObject, iTween.Hash("y", 270f, "time", 0.02f)); if (height == 1 && Physics.Raycast(transform.position, Vector3.down, out dice, maxDistance)) { if (dice.collider.tag == "dice" && !transparentFlag) { remoteDice = dice.collider.gameObject.GetComponent <DiceControll>(); remoteDice.ForwardRotate(); print("下にある、前方に移動"); } } if (height == 0 && Physics.Raycast(transform.position, Vector3.forward, out dice, maxDistance)) { if (dice.collider.tag == "dice") { remoteDice = dice.collider.gameObject.GetComponent <DiceControll>(); forceStop = remoteDice.ForwardSlide(); print("前方に移動"); } } if (forceStop == false && transparentFlag == false) //強制停止 透過フラグがtrueでない場合のみ { forceStop = true; //強制停止フラグ初期化 return; } f_posY -= 1; // 処理中のフラグをたてとく。 iTweenMoving = true; iTween.MoveAdd(this.gameObject, iTween.Hash( "x", 1, "time", 0.1f, "oncomplete", "OnCompleteHandler", "oncompletetarget", this.gameObject)); posY -= 1; //座標用数値変更 forceStop = true; //強制停止フラグ初期化 transparentFlag = false; //透過フラグ初期化 } if (!iTweenMoving && Input.GetKey("down") && posY <= 6 - 1)//↓ { iTween.RotateTo(this.gameObject, iTween.Hash("y", 90f, "time", 0.02f)); if (height == 1 && Physics.Raycast(transform.position, Vector3.down, out dice, maxDistance)) { if (dice.collider.tag == "dice" && !transparentFlag) { remoteDice = dice.collider.gameObject.GetComponent <DiceControll>(); remoteDice.BackRotate(); print("下にある、下方に移動"); } } if (Physics.Raycast(transform.position, Vector3.back, out dice, maxDistance)) { if (dice.collider.tag == "dice") { remoteDice = dice.collider.gameObject.GetComponent <DiceControll>(); forceStop = remoteDice.BackSlide(); print("下方に移動"); } } if (forceStop == false && transparentFlag == false) //強制停止 透過フラグがtrueでない場合のみ { forceStop = true; //強制停止フラグ初期化 return; } // 処理中のフラグをたてとく。 iTweenMoving = true; iTween.MoveAdd(this.gameObject, iTween.Hash( "x", 1, "time", 0.1f, "oncomplete", "OnCompleteHandler", "oncompletetarget", this.gameObject)); posY += 1; //座標用数値変更 forceStop = true; //強制停止フラグ初期化 transparentFlag = false; //透過フラグ初期化 } if (!iTweenMoving && Input.GetKey("left") && posX >= 1)//← { iTween.RotateTo(this.gameObject, iTween.Hash("y", 180f, "time", 0.02f)); if (height == 1 && Physics.Raycast(transform.position, Vector3.down, out dice, maxDistance)) { if (dice.collider.tag == "dice" && !transparentFlag) { remoteDice = dice.collider.gameObject.GetComponent <DiceControll>(); remoteDice.LeftRotate(); print("下にある、左方に移動"); } } if (Physics.Raycast(transform.position, Vector3.left, out dice, maxDistance)) { if (dice.collider.tag == "dice") { remoteDice = dice.collider.gameObject.GetComponent <DiceControll>(); forceStop = remoteDice.LeftSlide(); print("左方に移動"); } } if (forceStop == false && transparentFlag == false) //強制停止 透過フラグがtrueでない場合のみ { forceStop = true; //強制停止フラグ初期化 return; } // 処理中のフラグをたてとく。 iTweenMoving = true; iTween.MoveAdd(this.gameObject, iTween.Hash( "x", +1, "time", 0.1f, "oncomplete", "OnCompleteHandler", "oncompletetarget", this.gameObject)); posX -= 1; //座標用数値変更 forceStop = true; //強制停止フラグ初期化 transparentFlag = false; //透過フラグ初期化 } if (!iTweenMoving && Input.GetKey("right") && posX <= 6 - 1)//→ { iTween.RotateTo(this.gameObject, iTween.Hash("y", 0f, "time", 0.02f)); if (height == 1 && Physics.Raycast(transform.position, Vector3.down, out dice, maxDistance)) { if (dice.collider.tag == "dice" && !transparentFlag) { remoteDice = dice.collider.gameObject.GetComponent <DiceControll>(); remoteDice.RightRotate(); print("下にある、右方に移動"); } } if (Physics.Raycast(transform.position, Vector3.right, out dice, maxDistance)) { if (dice.collider.tag == "dice") { remoteDice = dice.collider.gameObject.GetComponent <DiceControll>(); forceStop = remoteDice.RightSlide(); print("右方に移動"); } } if (forceStop == false && transparentFlag == false) //強制停止 透過フラグがtrueでない場合のみ { forceStop = true; //強制停止フラグ初期化 return; } // 処理中のフラグをたてとく。 iTweenMoving = true; iTween.MoveAdd(this.gameObject, iTween.Hash( "x", 1, "time", 0.1f, "oncomplete", "OnCompleteHandler", "oncompletetarget", this.gameObject)); posX += 1; //座標用数値変更 forceStop = true; //強制停止フラグ初期化 transparentFlag = false; //透過フラグ初期化 } if (Input.GetKey(KeyCode.J)) { transparentFlag = true; } if (Input.GetKeyUp(KeyCode.J)) { transparentFlag = false; } if (stageSetting.objinfo[posX, posY]) { transform.position = new Vector3(transform.position.x, 1, transform.position.z); height = 1;//高さカウンター変更 } else if (!stageSetting.objinfo[posX, posY] && !Mathf.Approximately(transform.position.y, 0)) { if (!firstEntry) { return; } transform.position = new Vector3(transform.position.x, 0, transform.position.z); height = 0;//高さカウンター変更 } if (transform.position.y < 0) { transform.position = new Vector3(transform.position.x, 0, transform.position.z); transparentFlag = false; } }