예제 #1
0
    void OnTriggerStay(Collider other)
    {
        ControllerInput hand = other.gameObject.GetComponent <ControllerInput>();

        // If collider belongs to a hand
        if (hand != null)
        {
            // If hand is not holding anything
            if (hand.heldObjects.Count == 0 && hand.device.GetPress(EVRButtonId.k_EButton_SteamVR_Trigger))
            {
                // Assign new object to a random value inside hatObjects
                GameObject newObject = Instantiate(hatObjects[Random.Range(0, hatObjects.Count)]);
                newObject.transform.position = hand.transform.position;
                // Pick up object
                newObject.GetComponent <InteractableItem>().Pickup(hand);
                hand.GetComponent <ControllerInput>().heldObjects.Add(newObject.GetComponent <InteractableItem>());
                audioSource.PlayOneShot(takeOutClip);
            }
        }
    }