示例#1
0
    void FixedUpdate()
    {
        if (Input.GetMouseButtonDown(0))
        {
            Vector2    mPosScreen = Input.mousePosition;
            RaycastHit hit;
            Ray        ray = Camera.main.ScreenPointToRay(mPosScreen);       //


            if (Physics.Raycast(ray, out hit))
            {
                if (hit.collider.gameObject == this.gameObject)
                {
                    if (thisItem.canBeMoved == false)
                    {
                        return;
                    }
                    networkManager.SetItemMoveAuthority_sender(this.gameObject.name, false);


                    // set thisItem.thisClient_canModify_thisItem = false on every client except the active one
                    networkManager.RemoveClientAuthorityForItem_sender(this.gameObject.name);
                    GetComponent <ThisItem>().thisClient_canModify_thisItem = true;


                    hitGameObject  = hit.collider.gameObject;
                    isBeingDragged = true;
                }
            }
        }

        if (Input.GetMouseButton(0))
        {
            if (isBeingDragged == true)
            {
                RaycastHit hit;
                Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                if (Physics.Raycast(ray, out hit))
                {
                    Vector3 newPos = new Vector3(hit.point.x, this.transform.position.y, hit.point.z);
                    hitGameObject.transform.position = newPos;
                }
            }
        }

        if (Input.GetMouseButtonUp(0) || !(Input.GetMouseButton(0)))
        {
            if (isBeingDragged == true)
            {
                isBeingDragged = false;

                networkManager.SetItemMoveAuthority_sender(this.gameObject.name, true);             // cange bool thisItem.canBeMoved

                networkManager.SetAuthorityToHostOnly_sender(this.gameObject.name);                 // change bool thisItem.thisClient_canModify_thisItem
            }
        }
    }
示例#2
0
    /********************************************************
     * Prevent stuttering when this item moves another interactable item
     ******************************************************** */

    void OnCollisionEnter(Collision col)
    {
        // prevent stuttering on network
        if (col.gameObject.tag == "Item" && this.GetComponent <DraggableXZ>().isBeingDragged == true)
        {
            if (col.gameObject.GetComponent <ThisItem>().thisClient_canModify_thisItem != null)
            {
                //              print ("Success: Collision of " + this.gameObject.name + " with " + col.gameObject.name + ". Component Item + attribute canmodify exists");
                thatItem = col.gameObject;
                networkManager.RemoveClientAuthorityForItem_sender(thatItem.name);
                thatItem.GetComponent <ThisItem>().thisClient_canModify_thisItem = true;

                networkManager.SetItemMoveAuthority_sender(thatItem.name, false);
            }
        }
    }