- Home /
Raycast VR not working
I am trying to send out a raycast from the tip of my gun but it does not seem to be working can anyone spot why?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Weapon : MonoBehaviour {
private SteamVR_TrackedController controller;
private AudioSource audiosource;
private Animation anim;
public GameObject gunEnd;
public SteamVR_TrackedObject trackedObj;
private float weaponRange = 100f;
// Use this for initialization
private void Start () {
audiosource = GetComponent<AudioSource>();
controller = GetComponentInParent<SteamVR_TrackedController>();
anim = GetComponent<Animation>();
controller.TriggerClicked += FireWeapon;
}
private void FireWeapon(object sender, ClickedEventArgs e)
{
SteamVR_Controller.Input((int)trackedObj.index).TriggerHapticPulse(1000);
Debug.Log("SHOT");
audiosource.Play();
Shoot();
anim.Play();
}
private void Shoot()
{
RaycastHit hit;
Ray raycast = new Ray(gunEnd.transform.position, gunEnd.transform.forward);
if (Physics.Raycast(raycast, out hit, weaponRange))
{
Debug.Log(hit.transform.name);
}
}
// Update is called once per frame
void Update () {
}
}
Comment
Your answer
Follow this Question
Related Questions
How to make the swipe on Oculus Go 3 Answers
Firing mechanism not working (C#) 1 Answer
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers