コード例 #1
0
    /*void OnMouseDrag()
     * {
     *      trackedAngle += Input.GetAxis("Mouse X") * rotSpeed * Mathf.Deg2Rad;
     *
     *      if (Mathf.Abs(trackedAngle) >= mAngleBetweenPlayers)
     * {
     *              //currentAngle += trackedAngle;
     *              if (trackedAngle > 0)
     *              {
     *      mRestaurantScript.RotatePlatterRight();
     *                      trackedAngle = mAngleBetweenPlayers;
     *      GameObject.Find("GameplayManager").GetComponent<StartGameScript>().UpdateMealColors();
     *              }
     *              else
     *              {
     *      mRestaurantScript.RotatePlatterLeft();
     *                      trackedAngle = -mAngleBetweenPlayers;
     *      GameObject.Find("GameplayManager").GetComponent<StartGameScript>().UpdateMealColors();
     *  }
     *
     *              transform.Rotate(Vector3.forward, -trackedAngle);
     *
     *              trackedAngle = 0;
     *              currentAngle = transform.eulerAngles.z;
     *              //currentAngle = currentAngle * Mathf.Deg2Rad;
     *      }
     * }*/

    void Update()
    {
        if (mRestaurantScript.mIsAPlayerSelected)
        {
            if (mIsRotating)
            {
                //mMouseOffset = (Input.mousePosition - mMouseStartPosition);

                //Vector3 startToOrigin = Vector3.Normalize(Camera.main.WorldToScreenPoint(transform.position) - mMouseStartPosition);
                //Vector3 startToEnd = Vector3.Normalize(Input.mousePosition - mMouseStartPosition);

                //Debug.Log(Vector3.Dot(startToOrigin, startToEnd));

                //if (Vector3.Dot(startToOrigin, startToEnd) > 0)
                //{
                //    mAccumulatedAngle += mMouseOffset.x * mSensitivity;
                //    mRotation.z = mMouseOffset.x * mSensitivity;
                //}
                //else
                //{
                //    mAccumulatedAngle += -mMouseOffset.x * mSensitivity;
                //    mRotation.z = -mMouseOffset.x * mSensitivity;
                //}

                //transform.Rotate(mRotation);

                //mMouseStartPosition = Input.mousePosition;

                //if (mAccumulatedAngle > mAngleBetweenPlayers)
                //{
                //    mRestaurantScript.RotatePlatterLeft();
                //    mPrevRotation += mAngleBetweenPlayers;
                //    mAccumulatedAngle = 0;
                //    GameObject.Find("GameplayManager").GetComponent<StartGameScript>().UpdateMealColors();
                //}
                //else if (mAccumulatedAngle < -mAngleBetweenPlayers)
                //{
                //    mRestaurantScript.RotatePlatterRight();
                //    mPrevRotation += mAngleBetweenPlayers;
                //    mAccumulatedAngle = 0;
                //    GameObject.Find("GameplayManager").GetComponent<StartGameScript>().UpdateMealColors();
                //}

                mMouseOffset = (Input.mousePosition - mMouseReference);

                if (Camera.main.WorldToScreenPoint(transform.position).y > Input.mousePosition.y)
                {
                    mAccumulatedAngle += mMouseOffset.x * mSensitivity;
                    mRotation.z        = mMouseOffset.x * mSensitivity;
                }
                else
                {
                    mAccumulatedAngle += -mMouseOffset.x * mSensitivity;
                    mRotation.z        = -mMouseOffset.x * mSensitivity;
                }

                transform.Rotate(mRotation);

                mMouseReference = Input.mousePosition;

                if (mAccumulatedAngle > mAngleBetweenPlayers)
                {
                    mRestaurantScript.RotatePlatterLeft();
                    mPrevRotation    += mAngleBetweenPlayers;
                    mAccumulatedAngle = 0;
                    mIsRotated        = true;

                    if (mRestaurantScript.mSelectedPlayer.getLastMealEaten() != EnumSpecialMeal.TRICKSTER)
                    {
                        GameObject.Find("GameplayManager").GetComponent <StartGameScript> ().UpdateMealColors();
                    }
                }
                else if (mAccumulatedAngle < -mAngleBetweenPlayers)
                {
                    mRestaurantScript.RotatePlatterRight();
                    mPrevRotation    += mAngleBetweenPlayers;
                    mAccumulatedAngle = 0;
                    mIsRotated        = true;

                    if (mRestaurantScript.mSelectedPlayer.getLastMealEaten() != EnumSpecialMeal.TRICKSTER)
                    {
                        GameObject.Find("GameplayManager").GetComponent <StartGameScript> ().UpdateMealColors();
                    }
                }
            }
        }
    }