public void OnMouseDown() { //print("Left Clicked"); if (!Physics2D.OverlapCircle(new Vector3(transform.position.x - gridSize, transform.position.y, transform.position.z), 0.2f, movementBlock)) { if (Physics2D.OverlapCircle(new Vector3(transform.position.x - gridSize, transform.position.y, transform.position.z), 0.2f, sandMask)) { sand = Physics2D.OverlapCircle(new Vector3(transform.position.x - gridSize, transform.position.y, transform.position.z), 0.2f, sandMask).GetComponent <Sand>(); sand.SandLeftCheck(); if (sand.sandMove == true) { slidingBlock.LeftTrigger(); } } else { slidingBlock.LeftTrigger(); } } else { FindObjectOfType <AudioManager>().Play("pieceStopped"); } }
// Update is called once per frame void Update() { transform.position = Vector3.MoveTowards(transform.position, movePoint.position, moveSpeed * Time.deltaTime); if (movementEnabled == true) { if (Input.GetKeyDown(KeyCode.A) || Input.GetKeyDown(KeyCode.LeftArrow))//Left { if (!Physics2D.OverlapCircle(new Vector3(movePoint.position.x - gridSize, movePoint.position.y, movePoint.position.z), 0.2f, movementBlock)) { if (Physics2D.OverlapCircle(new Vector3(movePoint.position.x - gridSize, movePoint.position.y, movePoint.position.z), 0.2f, sandMask)) { sand = Physics2D.OverlapCircle(new Vector3(movePoint.position.x - gridSize, movePoint.position.y, movePoint.position.z), 0.2f, sandMask).GetComponent <Sand>(); if (sand != null) { sand.SandLeftCheck(); canSandMove = sand.sandMove; if (canSandMove == true) { FindObjectOfType <AudioManager>().Play("objectSlide"); movePoint.position = new Vector3(movePoint.position.x - gridSize, movePoint.position.y, movePoint.position.z); } } } else { FindObjectOfType <AudioManager>().Play("objectSlide"); movePoint.position = new Vector3(movePoint.position.x - gridSize, movePoint.position.y, movePoint.position.z); FindObjectOfType <DialogueManager>().objectMoveTrigger(); } } else { FindObjectOfType <AudioManager>().Play("pieceStopped"); } if (onCorrectForm == true) { partManager.numOfParts++; onCorrectForm = false; } } else if (Input.GetKeyDown(KeyCode.S) || Input.GetKeyDown(KeyCode.DownArrow)) //Down { if (!Physics2D.OverlapCircle(new Vector3(movePoint.position.x, movePoint.position.y - gridSize, movePoint.position.z), 0.2f, movementBlock)) { if (Physics2D.OverlapCircle(new Vector3(movePoint.position.x, movePoint.position.y - gridSize, movePoint.position.z), 0.2f, sandMask)) { sand = Physics2D.OverlapCircle(new Vector3(movePoint.position.x, movePoint.position.y - gridSize, movePoint.position.z), 0.2f, sandMask).GetComponent <Sand>(); if (sand != null) { sand.SandDownCheck(); canSandMove = sand.sandMove; if (canSandMove == true) { FindObjectOfType <AudioManager>().Play("objectSlide"); movePoint.position = new Vector3(movePoint.position.x, movePoint.position.y - gridSize, movePoint.position.z); } } } else { FindObjectOfType <AudioManager>().Play("objectSlide"); movePoint.position = new Vector3(movePoint.position.x, movePoint.position.y - gridSize, movePoint.position.z); FindObjectOfType <DialogueManager>().objectMoveTrigger(); } } else { FindObjectOfType <AudioManager>().Play("pieceStopped"); } if (onCorrectForm == true) { partManager.numOfParts++; onCorrectForm = false; } } else if (Input.GetKeyDown(KeyCode.D) || Input.GetKeyDown(KeyCode.RightArrow)) //Right { if (!Physics2D.OverlapCircle(new Vector3(movePoint.position.x + gridSize, movePoint.position.y, movePoint.position.z), 0.2f, movementBlock)) { if (Physics2D.OverlapCircle(new Vector3(movePoint.position.x + gridSize, movePoint.position.y, movePoint.position.z), 0.2f, sandMask)) { sand = Physics2D.OverlapCircle(new Vector3(movePoint.position.x + gridSize, movePoint.position.y, movePoint.position.z), 0.2f, sandMask).GetComponent <Sand>(); if (sand != null) { sand.SandRightCheck(); canSandMove = sand.sandMove; if (canSandMove == true) { FindObjectOfType <AudioManager>().Play("objectSlide"); movePoint.position = new Vector3(movePoint.position.x + gridSize, movePoint.position.y, movePoint.position.z); } } } else { FindObjectOfType <AudioManager>().Play("objectSlide"); movePoint.position = new Vector3(movePoint.position.x + gridSize, movePoint.position.y, movePoint.position.z); FindObjectOfType <DialogueManager>().objectMoveTrigger(); } } else { FindObjectOfType <AudioManager>().Play("pieceStopped"); } if (onCorrectForm == true) { partManager.numOfParts++; onCorrectForm = false; } } else if (Input.GetKeyDown(KeyCode.W) || Input.GetKeyDown(KeyCode.UpArrow)) //Up { if (!Physics2D.OverlapCircle(new Vector3(movePoint.position.x, movePoint.position.y + gridSize, movePoint.position.z), 0.2f, movementBlock)) { if (Physics2D.OverlapCircle(new Vector3(movePoint.position.x, movePoint.position.y + gridSize, movePoint.position.z), 0.2f, sandMask)) { sand = Physics2D.OverlapCircle(new Vector3(movePoint.position.x, movePoint.position.y + gridSize, movePoint.position.z), 0.2f, sandMask).GetComponent <Sand>(); if (sand != null) { sand.SandUpCheck(); canSandMove = sand.sandMove; if (canSandMove == true) { FindObjectOfType <AudioManager>().Play("objectSlide"); movePoint.position = new Vector3(movePoint.position.x, movePoint.position.y + gridSize, movePoint.position.z); } } } else { FindObjectOfType <AudioManager>().Play("objectSlide"); movePoint.position = new Vector3(movePoint.position.x, movePoint.position.y + gridSize, movePoint.position.z); FindObjectOfType <DialogueManager>().objectMoveTrigger(); } } else { FindObjectOfType <AudioManager>().Play("pieceStopped"); } if (onCorrectForm == true) { partManager.numOfParts++; onCorrectForm = false; } } } if (Physics2D.OverlapCircle(transform.position, 0.2f, correctLayer)) { onCorrectForm = true; } else { onCorrectForm = false; } if (onCorrectForm == true && victoryNoiseTrigger == false) { FindObjectOfType <AudioManager>().Play("correctSlot"); victoryNoiseTrigger = true; } else if (onCorrectForm == false) { //print("false triggered"); victoryNoiseTrigger = false; } }