예제 #1
0
    // Update is called once per frame
    void Update()
    {
        if (_Logic.playerTurn == true)
        {
            if (holdingPiece == true)
            {
                Vector3 forwardDir = raycastHolder.transform.TransformDirection(Vector3.forward) * 100;

                Debug.DrawRay(raycastHolder.transform.position, forwardDir, Color.green);

                if (Physics.Raycast(raycastHolder.transform.position, (forwardDir), out hit))
                {
                    gravityAttractor.transform.position = new Vector3(hit.point.x, hit.point.y + hoverHeight, hit.point.z);

                    //pieceBeingHeld.GetComponent<Rigidbody> ().useGravity = false;
                    //pieceBeingHeld.GetComponent<BoxCollider> ().enabled = false;

                    //pieceBeingHeld.GetComponent<Rigidbody>().AddForce(gravityAttractor.transform.position - pieceBeingHeld.transform.position);


                    piece.inPlay(gravityAttractor.transform.position);

                    if (hit.collider.gameObject.tag == "Grid Plate")
                    {
                        if (Input.GetMouseButtonDown(0))
                        {
                            holdingPiece = false;
                            hit.collider.gameObject.SetActive(false);

                            //pieceBeingHeld.GetComponent<PlayerPiece>().hasBeenPlayed = true;
                            piece.playPiece(new Vector3(hit.point.x, hit.point.y, hit.point.z));

                            //pieceBeingHeld.GetComponent<Rigidbody> ().useGravity = true;
                            //pieceBeingHeld.GetComponent<BoxCollider> ().enabled = true;
                            GameLogic.GetComponent <GameLogic>().playerMove(hit.collider.gameObject);
                        }
                        else
                        {
                        }
                    }
                }
            }
        }
    }