コード例 #1
0
    // Update is called once per frame
    void Update()
    {
        var        currentPosition = transform.position;
        Ray        ray             = new Ray(currentPosition, transform.forward);
        RaycastHit hit;
        bool       isHit = Physics.Raycast(ray, out hit, Mathf.Infinity);

        if (isHit)
        {
            var point    = hit.point;
            var distance = Vector3.Distance(currentPosition, point);
            mLeftDistance.text  = distance.ToString("F4");
            mRightDistance.text = distance.ToString("F4");
        }
        else
        {
            mLeftDistance.text  = "∞";
            mRightDistance.text = "∞";
        }

        if (Input.GetKeyDown(KeyCode.JoystickButton0))
        {
            GameObject    canvas = GameObject.Find("Canvas");
            CanvasManager cm     = canvas.GetComponent <CanvasManager>();
            if (isHit && hit.collider.gameObject.tag.Equals("UI") || cm.mUIIsShow)
            {
                return;
            }
            else
            {
                if (mChecker == null)
                {
                    mChecker        = Instantiate(mPerfabChecker, transform.position + transform.forward * mCheckerDistance, Quaternion.identity);
                    mCheckerManager = mChecker.GetComponent <CheckerManager>();
                }
                else
                {
                    mChecker.transform.position = transform.position + transform.forward * mCheckerDistance;
                }

                mCheckerManager.resetLocalRotation();
                mCheckerManager.resetLocalPosition();
                mChecker.transform.LookAt(transform);
            }
        }
    }