void Start() { Player = this.gameObject; NewCubePrefab = Resources.Load <Rigidbody>("New Cube"); PrefabMoveingStop = Resources.Load <GameObject>("Collider To stop Moveing"); Players = GameObject.FindObjectsOfType <PlayerMovements>(); for (int Number = 0; Number < Players.Length; Number++) { if (gameObject.name == "Cube(" + Number + ")") { FirstNumber = Number - 1; SecondNumber = Number + 1; CubesCountsNumber = Number; } } StartPostion = gameObject.transform.position; Center.transform.position = new Vector3(Player.transform.position.x, Player.transform.position.y - StartPostion.y, Player.transform.position.z); CenterControl.transform.position = new Vector3(Player.transform.position.x, 2, Player.transform.position.z); UpControl.GetComponent <PlayerTriggerControl>().isTrigger = DownControl.GetComponent <PlayerTriggerControl>().isTrigger = leftControl.GetComponent <PlayerTriggerControl>().isTrigger = RightControl.GetComponent <PlayerTriggerControl>().isTrigger = null; UpControl.GetComponent <PlayerTriggerControl>().PlayerMove = DownControl.GetComponent <PlayerTriggerControl>().PlayerMove = leftControl.GetComponent <PlayerTriggerControl>().PlayerMove = RightControl.GetComponent <PlayerTriggerControl>().PlayerMove = true; }
void Update() { if (gameObject.name == "New Cube(Clone)") { if (GameManager.Instans.GameOver == true) { return; } if (i == 1) { FirstNumber = Player2.FirstNumber; SecondNumber = Player2.SecondNumber; CubesCountsNumber = Player2.CubesCountsNumber; } else { FirstNumber = Player1.FirstNumber; SecondNumber = Player1.SecondNumber; CubesCountsNumber = Player1.CubesCountsNumber; } } if (isInputRestricted == true) { if (isTouch == true) { Center.transform.position = new Vector3(Player.transform.position.x, Player.transform.position.y - StartPostion.y, Player.transform.position.z); CenterControl.transform.position = new Vector3(Player.transform.position.x, 2, Player.transform.position.z); if (MoveUpSideCube == false) { if (UpControl.GetComponent <PlayerTriggerControl>().PlayerMove == false) { if (UpControl.GetComponent <PlayerTriggerControl>().isTrigger.GetComponent <PlayerMovements>().StartPostion.y > StartPostion.y) { Up.transform.position = new Vector3(Up.transform.position.x, StartPostion.y * 2, Up.transform.position.z); } else { Up.transform.position = new Vector3(Up.transform.position.x, UpControl.GetComponent <PlayerTriggerControl>().isTrigger.transform.position.y + Player.transform.position.y, Up.transform.position.z); } } else { Up.transform.position = new Vector3(Up.transform.position.x, Player.transform.position.y, Up.transform.position.z); } if (DownControl.GetComponent <PlayerTriggerControl>().PlayerMove == false) { if (DownControl.GetComponent <PlayerTriggerControl>().isTrigger.transform.position.y > StartPostion.y) { Down.transform.position = new Vector3(Down.transform.position.x, StartPostion.y * 2, Down.transform.position.z); } else { Down.transform.position = new Vector3(Down.transform.position.x, DownControl.GetComponent <PlayerTriggerControl>().isTrigger.transform.position.y + Player.transform.position.y, Down.transform.position.z); } } else { Down.transform.position = new Vector3(Down.transform.position.x, Player.transform.position.y, Down.transform.position.z); } if (leftControl.GetComponent <PlayerTriggerControl>().PlayerMove == false) { if (leftControl.GetComponent <PlayerTriggerControl>().isTrigger.transform.position.y > StartPostion.y) { left.transform.position = new Vector3(left.transform.position.x, StartPostion.y * 2, left.transform.position.z); } else { left.transform.position = new Vector3(left.transform.position.x, leftControl.GetComponent <PlayerTriggerControl>().isTrigger.transform.position.y + Player.transform.position.y, left.transform.position.z); } } else { left.transform.position = new Vector3(left.transform.position.x, Player.transform.position.y, left.transform.position.z); } if (RightControl.GetComponent <PlayerTriggerControl>().PlayerMove == false) { if (RightControl.GetComponent <PlayerTriggerControl>().isTrigger.transform.position.y > StartPostion.y) { Right.transform.position = new Vector3(Right.transform.position.x, StartPostion.y * 2, Right.transform.position.z); } else { Right.transform.position = new Vector3(Right.transform.position.x, RightControl.GetComponent <PlayerTriggerControl>().isTrigger.transform.position.y + Player.transform.position.y, Right.transform.position.z); } } else { Right.transform.position = new Vector3(Right.transform.position.x, Player.transform.position.y, Right.transform.position.z); } } if (Input.GetKeyDown(KeyCode.UpArrow)) { if (UpSide.PlayerMove == false) { UpMove = true; } else { if (UpStop == false) { StartCoroutine(RotationControal(Up, Vector3.right, -180)); isInputRestricted = false; StopMoveing.SetActive(true); } } } if (Input.GetKeyDown(KeyCode.DownArrow)) { if (DownSide.PlayerMove == false) { DownMove = true; } else { if (DownStop == false) { StartCoroutine(RotationControal(Down, Vector3.left, 180)); isInputRestricted = false; StopMoveing.SetActive(true); } } } if (Input.GetKeyDown(KeyCode.RightArrow)) { if (RightSide.PlayerMove == false) { RightMove = true; } else { if (RightStop == false) { StartCoroutine(RotationControal(Right, Vector3.back, -90)); isInputRestricted = false; StopMoveing.SetActive(true); } } } if (Input.GetKeyDown(KeyCode.LeftArrow)) { if (LeftSide.PlayerMove == false) { LeftMove = true; } else { if (LeftStop == false) { StartCoroutine(RotationControal(left, Vector3.forward, 90)); isInputRestricted = false; StopMoveing.SetActive(true); } } } } } if (isTouch == true) { if (isInputRestricted == true) { HandleInput(); } } if (UpMove == true) { if (UpSide.PlayerMove == false) { MoveUpSideCube = true; transform.Translate(0, force[i], 0); } else { StartCoroutine(RotationControal(Up, Vector3.right, -180)); isInputRestricted = false; UpMove = false; MoveUpSideCube = false; StopMoveing.SetActive(true); } } if (DownMove == true) { if (DownSide.PlayerMove == false) { MoveUpSideCube = true; transform.Translate(0, force[i], 0); } else { StartCoroutine(RotationControal(Down, Vector3.left, 180)); isInputRestricted = false; DownMove = false; MoveUpSideCube = false; StopMoveing.SetActive(true); } } if (LeftMove == true) { if (LeftSide.PlayerMove == false) { MoveUpSideCube = true; transform.Translate(0, force[i], 0); } else { StartCoroutine(RotationControal(left, Vector3.forward, 90)); isInputRestricted = false; LeftMove = false; MoveUpSideCube = false; StopMoveing.SetActive(true); } } if (RightMove == true) { if (RightSide.PlayerMove == false) { MoveUpSideCube = true; transform.Translate(0, force[i], 0); } else { StartCoroutine(RotationControal(Right, Vector3.back, -90)); isInputRestricted = false; RightMove = false; MoveUpSideCube = false; StopMoveing.SetActive(true); } } }