Exemplo n.º 1
0
    void OnMouseDown()
    {
        float camdist = Vector3.Distance(FPCam.transform.parent.position, transform.position);

        MouseDown = true;
        FPCam.transform.parent.GetComponent <RoadBuilder>().Dragging = true;
        RaycastHit hit;

        ray = FPCam.ScreenPointToRay(Input.mousePosition);
        if (Physics.Raycast(ray, out hit))
        {
            if (hit.collider.bounds.extents.y < 1)
            {
                _dragDirection = "xz";
            }
            else
            {
                _dragDirection = "y";
            }
        }
        FPCam.transform.parent.GetComponent <BuilderCamController>().FreezeTilt = true;
        ObjStartPos = AttachedTransform.position;
        if (_dragDirection == "xz")
        {
            LerpEndPt = AttachedTransform.position + _hoverPos + Vector3.up * camdist;
        }
        else
        {
            //WOrk out where to lerp the cam to
            Vector3 Offset = (FPCam.transform.position - transform.position).normalized;
            LerpEndPt = FPCam.transform.position; // transform.position + Offset * _hoverHeight*3;
        }
        LerpStartRot  = FPCam.transform.rotation;
        LerpStartPt   = FPCam.transform.position;
        LerpStartTime = Time.time;
        Lerping       = true;
        Debug.Log("Lerp to " + LerpEndPt);
        AttachedObject.DisableClickColliders();
        //transform.LookAt(FPCam.transform);
    }