private void OnCollisionEnter(Collision collision) { if ((collision.gameObject.layer == LayerMask.NameToLayer("Tile") || collision.gameObject.layer == LayerMask.NameToLayer("StartTile")) && isFalling) { if (collision.gameObject.layer == LayerMask.NameToLayer("StartTile")) { isStarted = true; } isFalling = false; cmyk += CMYK.RGBToCMYK(collision.gameObject.GetComponent <MeshRenderer>().material.color); GetComponent <MeshRenderer>().material.color = cmyk.CMYKToRGB(); rigidbody.AddForce(collision.gameObject.transform.up * 600, ForceMode.Acceleration); } else if (collision.gameObject.layer == LayerMask.NameToLayer("DestTile")) { Debug.Log("finished"); Time.timeScale = 0; if (CalculateScore(CMYK.RGBToCMYK(collision.gameObject.GetComponent <MeshRenderer>().material.color), cmyk)) { gameManager.fsm.next = StateType.Clear; } else { gameManager.fsm.next = StateType.Result; } } if (scope != null) { RaycastHit hit; Physics.Raycast(transform.position, transform.up * (-1), out hit); scope.transform.position = hit.point + (transform.forward.normalized * 18.44998f) + new Vector3(0, 0.001f, 0); } }
// Update is called once per frame void FixedUpdate() { //공중에 있는시간 : 2.459998 앞으로 가는거리 : 18.44998 if (gameManager.fsm.current != StateType.InGame && canMove) { canMove = false; Debug.Log("CannotMove"); } else if (gameManager.fsm.current == StateType.InGame && !canMove) { canMove = true; Debug.Log("CanMove"); } if (Input.touchCount > 0) { touch = Input.GetTouch(0); } if (canMove) { if (Input.GetKey(KeyCode.LeftArrow) || touch.position.x < 0) { scope.transform.SetParent(transform); transform.Rotate(transform.up, (-1) * angle); scope.transform.SetParent(null); } if (Input.GetKey(KeyCode.RightArrow) || touch.position.x > 0) { scope.transform.SetParent(transform); transform.Rotate(transform.up, angle); scope.transform.SetParent(null); } if (transform.position.y <= -10 && gameManager.fsm.current != StateType.GameOver) { gameManager.fsm.next = StateType.GameOver; } } if (cmyk.CMYKToRGB() == Color.black) { gameManager.fsm.next = StateType.GameOver; } if (rigidbody.velocity.y <= 0 && transform.position.y >= 5) { isFalling = true; } if (isStarted) { transform.Translate((transform.forward.normalized) * speed, Space.World); } nextcmyk = GetColorUnderScope(); }