Quantcast
Channel: Questions in topic: "gun"
Viewing all articles
Browse latest Browse all 592

Please help me solve the problem with shoot a gun(HTC VIVE)

$
0
0
How to attach shooting gun to my eyes???(HTC vive) When I press the button on the controller, it should fire from my eyes. But it doesn't work! please help me what to do!! I really need your help! Please save my life -------------> click on the link: https://youtu.be/_TYlZTRWirA There are two scrips(1. VRYK_ObjectAutoGrab//2.Gun) to attach the gun to front view of camera. ------------------------------------------------------------------------------------------------------------------------------------------- // 1. VRYK_ObjectAutoGrab namespace VRTK { using UnityEngine; using System.Collections; public class VRTK_ObjectAutoGrab : MonoBehaviour { public VRTK_InteractableObject objectToGrab; public bool cloneGrabbedObject; private VRTK_InteractGrab controller; private IEnumerator Start() { controller = GetComponent(); if (!controller) { Debug.LogError("The VRTK_InteractGrab script is required to be attached to the controller along with this script."); yield break; } VRTK_InteractableObject grabbableObject = objectToGrab; if (cloneGrabbedObject) { grabbableObject = Instantiate(objectToGrab); } controller.GetComponent().ForceStopTouching(); controller.GetComponent().ForceTouch(grabbableObject.gameObject); controller.AttemptGrab(); } } } //2. Gun using UnityEngine; using VRTK; public class Gun : VRTK_InteractableObject { public static Camera main; private GameObject bullet; private float bulletSpeed = 2000f; private float bulletLife = 1f; private AudioSource gunAudio; public override void StartUsing(GameObject usingObject) { main = GetComponentInParent(); base.StartUsing(usingObject); FireBullet(); } protected override void Start() { gunAudio = GetComponent(); base.Start(); bullet = transform.Find("Bullet").gameObject; bullet.SetActive(false); } private void FireBullet() { GameObject bulletClone = Instantiate(bullet, bullet.transform.position, bullet.transform.rotation) as GameObject; bulletClone.SetActive(true); Rigidbody rb = bulletClone.GetComponent(); rb.AddForce(-bullet.transform.forward * bulletSpeed); Destroy(bulletClone, bulletLife); } }

Viewing all articles
Browse latest Browse all 592

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>