Example #1
0
 private void SpawnObjectInHand(NVRHand hand)
 {
     if (hand.Inputs[NVRButtons.Grip].PressDown)
     {
         if (inevtoryController.RemovefromInventory(typeToRemove))
         {
             Debug.Log("Successfully removed item");
             //Spawn an object and make the hand interact with it
             GameObject       spawnedObject = (GameObject)Instantiate(prefabToSpawn, transform.position, transform.rotation);
             ExplosionEnabler rocket        = prefabToSpawn.GetComponent <ExplosionEnabler>();
             if (rocket)
             {
                 rocket.playerHealth = leftHand.GetComponent <HealthBarController>();
             }
             Medicine med = prefabToSpawn.GetComponent <Medicine>();
             if (med)
             {
                 Debug.Log("Spawned Medicine in hand");
                 med.health = leftHand.GetComponent <HealthBarController>();
                 med.head   = GameObject.Find("Head").GetComponent <NVRHead>();
             }
             PickableItem item = spawnedObject.GetComponent <PickableItem>();
             if (item != null)
             {
                 hand.BeginInteraction(item);
                 //TODO: Remove velocity
                 item.gameObject.GetComponent <Rigidbody>().velocity = new Vector3(0.0f, 0.0f, 0.0f);
             }
             else
             {
                 hand.BeginInteraction(spawnedObject.GetComponent <NVRExampleGun>());
             }
         }
     }
 }
 void Update()
 {
     if (swordUI.FireIsDepleted())
     {
         return;
     }
     if (attachedGun.gameObject.activeSelf)
     {
         return;
     }
     if (attachedHand.HoldButtonDown)
     {
         if (attachedHand.CurrentlyInteracting == null)
         {
             VibrateController();
             PrepareShuriken();
             attachedHand.BeginInteraction(instantiatedShuriken.GetComponent <NVRInteractableItem>());
         }
     }
     else if (attachedHand.HoldButtonUp)
     {
         if (attachedHand.CurrentlyInteracting != null)
         {
             if (attachedHand.CurrentlyInteracting.gameObject.CompareTag("Shuriken"))
             {
                 if (instantiatedShuriken != null)
                 {
                     if (attachedHand.CurrentlyInteracting == instantiatedShuriken.GetComponent <NVRInteractableItem>())
                     {
                         VibrateController();
                         attachedHand.EndInteraction(instantiatedShuriken.GetComponent <NVRInteractableItem>());
                         swordUI.DepleteFire(usageCost);
                         instantiatedShuriken.GetComponent <Rigidbody>().AddForce(instantiatedShuriken.GetComponent <Rigidbody>().velocity.normalized);
                         instantiatedShuriken.GetComponent <Shuriken>().SetThrown(true);
                         PlayShurikenNoise();
                         StartCoroutine("ShootShurikens");
                         StartCoroutine("ShootWaitTime");
                     }
                 }
             }
         }
     }
 }
        public override void HoveringUpdate(NVRHand hand, float forTime)
        {
            base.HoveringUpdate(hand, forTime);

            if (IsAttached == false)
            {
                if (forTime > PickupAfterSeconds)
                {
                    hand.BeginInteraction(this);
                }
            }
        }