コード例 #1
0
 public void PickUp(Holdable holdable)
 {
     if (holdable.GetComponent <CatBehavior>() != null) // if cat
     {
         holdable.GetComponent <BoxCollider2D>().offset = Vector3.up * -1.6f;
         holdable.GetComponent <BoxCollider2D>().size   = new Vector2 {
             x = .1f, y = .1f
         };
         Debug.Log("cat hitbox moved to feet");
     }
     holdable.transform.SetParent(this.transform);
     holdable.transform.localPosition = Vector3.up * 1;
     this.heldObject = holdable;
 }
コード例 #2
0
    private void Update()
    {
        if (heldObject != null && heldObject.GetComponent <Fence>() != null)
        {
            //calculate the tile we want to place on
            Vector3 footposition = this.transform.position - new Vector3 {
                x = 0f, y = -.65f, z = 0f
            };

            Vector3Int cellCoordinate = groundTilemap.WorldToCell(footposition);
            //place tile
            if (previousTile != cellCoordinate)
            {
                groundTilemap.SetTile(previousTile, null);
            }
            groundTilemap.SetTile(cellCoordinate, highlightTile);
            previousTile = cellCoordinate;
        }
    }
コード例 #3
0
        public override void OnStay()
        {
            Vector3 delta = (pt.holdableTarget.position - holdable.transform.position);

            holdable.GetComponent <Rigidbody>().velocity = delta.normalized * Mathf.Pow(delta.magnitude, 2) * pt.holdableSnapSpeed;
            // holdable.GetComponent<Rigidbody>().angularVelocity = Vector3.zero;
            if (delta.magnitude > pt.maxHoldableDistance || Input.GetMouseButtonDown(0))
            {
                pt.sm.Next(new NotHoldingState());
            }
        }
コード例 #4
0
    public override void ContentArrive(Holdable thingArriving)
    {
        if (OnContentArrive != null)
        {
            OnContentArrive.Invoke();
        }

        if (thingArriving != null)
        {
            var p = thingArriving.GetComponent <Pizza>();
            if (p != null)
            {
                OnPizzaArrive.Invoke(p);
            }
        }
    }
コード例 #5
0
ファイル: ShootMiniGame.cs プロジェクト: rendoir/feup-rvau
    public void Shoot(SteamVR_Action_Boolean action, SteamVR_Input_Sources sources)
    {
        if (!isPlayerInside || !isPlayerPlaying || !isGunAttached)
        {
            return;
        }

        // Check if action source matches the hand with the gun
        if (hand.handType != sources)
        {
            return;
        }

        gun.GetComponent <Gun>().OnShoot();


        GameObject bullet = Instantiate(bulletPrefab, gunRef.transform.position + gunRef.transform.forward * bulletForwardOffset + gunRef.transform.up * bulletUpOffset, gunRef.transform.rotation);

        bullet.transform.Rotate(90f, 0f, 0f);
        bullet.GetComponent <Rigidbody>().AddForce(Bullet.force * gunRef.transform.forward);
        bullets--;
    }
コード例 #6
0
ファイル: Debug_Input.cs プロジェクト: Tuuga/vr-stuff
    void Update()
    {
        // Hold an object
        if (Input.GetKeyDown(KeyCode.E) && holdable != null)
        {
            currentlyHolding = holdable;
            currentlyHolding.Hold(transform);
        }

        // Holds and snaps an object
        if (Input.GetKeyDown(KeyCode.R) && holdable != null)
        {
            currentlyHolding = holdable;
            currentlyHolding.HoldSnap(transform);
        }

        // Drops the held object
        if ((Input.GetKeyUp(KeyCode.E) || Input.GetKeyUp(KeyCode.R)) && currentlyHolding != null)
        {
            currentlyHolding.Drop(rb.velocity, rb.angularVelocity);
            currentlyHolding = null;
        }

        // Hold snap toggle
        if (Input.GetKeyDown(KeyCode.T))
        {
            if (!holdToggle && holdable != null)
            {
                currentlyHolding = holdable;
                currentlyHolding.HoldSnap(transform);
                holdToggle = true;
            }
            else if (holdToggle && currentlyHolding != null)
            {
                currentlyHolding.Drop(rb.velocity, rb.angularVelocity);
                currentlyHolding = null;
                holdToggle       = false;
            }
        }

        // Press button
        if (Input.GetKeyDown(KeyCode.F) && button != null)
        {
            button.Press();
        }

        if (Input.GetKey(KeyCode.E) && slider != null)
        {
            slider.Move(transform);
        }

        // If held object is gun, shoot
        if (Input.GetMouseButtonDown(0) && currentlyHolding != null)
        {
            var gun = currentlyHolding.GetComponent <Shooting>();
            if (gun != null)
            {
                gun.Shoot();
            }
        }

        if (Input.GetMouseButtonDown(1))
        {
            Teleport.Tele(transform.parent, transform.parent);
        }
    }
コード例 #7
0
    /*=================ITEMS===================*/

    //items are added to/removed from holdables list by the pickup_range object's script
    //the holdables list is an up-to-date list of all current objects that can be picked up

    void handleItems()
    {
        if (grabbed)
        {
            if (rightHandItem == null)
            {
                grab(rightHand, ref rightHandItem);
            }
            else if (leftHandItem == null)
            {
                grab(leftHand, ref leftHandItem);
            }
        }

        if (dropped)
        {
            if (leftHandItem != null)
            {
                drop(ref leftHandItem);
            }
            else if (rightHandItem != null)
            {
                drop(ref rightHandItem);
            }
        }

        if (combined)
        {
            combine();
        }

        if (used)
        {
            if (rightHandItem is ComplexObject)
            {
                ((ComplexObject)rightHandItem).use();
            }
            else if (leftHandItem is ComplexObject)
            {
                ((ComplexObject)leftHandItem).use();
            }
        }

        if (rightHandItem != null && rightHandItem.shape == "balloon")
        {
            //we're holding a balloon
            balloon = true;
            Balloon b = rightHandItem.GetComponent <Balloon>();
            if (b.popped)
            {
                rightHandItem.drop();
                rightHandItem = null;
            }
        }
        else if (leftHandItem != null && leftHandItem.shape == "balloon")
        {
            //we're holding a balloon
            balloon = true;
            Balloon b = leftHandItem.GetComponent <Balloon>();
            if (b.popped)
            {
                leftHandItem.drop();
                leftHandItem = null;
            }
        }
        else
        {
            //no balloon
            balloon = false;
        }
    }