Hello,
I am developing a game using the SteamVR plugin, and am currently attempting to have my laserPointer
script interact with a buttonPanel
script. The button panel uses hit.collider.tag
to determine which button has been hit by the laserPointer's
Raycasthit
variable. However, I get a NullReferenceException at the line where hit.collider.tag
lies.
Additionally, I used the laserPointer
script found here. I haven’t changed the code in this script, however, I am getting an error on the line where the script is supposed to get and then return the index of the controller. Is there any way I can communicate between multiple scripts to have these two scripts interact? I have already tried using static variables, getting the script component from the GameObject that has the script. Is there anything else I can do?
Thanks!
//laserPointer
private SteamVR_Controller.Device Controller
{
get { return SteamVR_Controller.Input((int)trackedObj.index); }
}
void Update()
{
if (Controller.GetPress (SteamVR_Controller.ButtonMask.Touchpad)) {
RaycastHit hit;
if (Physics.Raycast (trackedObj.transform.position, transform.forward, out hit, 100)) {
hitPoint = hit.point;
ShowLaser (hit);
}
}
else {
laser.SetActive (false);
}
}
//buttonPanel
public RaycastHit hitt;
public Vector3 hitPoint;
void Start () {
scene = SceneManager.GetActiveScene();
hitt = LaserPointer.hit;
hitPoint = LaserPointer.hitPoint;
}
void Update () {
for (int i = 0; i < buttons.Length; i++) { //goes through array of button tags
//THE LINE BELOW IS WHERE THE NULLREFERENCEEXCEPTION IS HAPPENING
if (hitt.collider.tag == buttons[i] || buttonHit == true) //if the laser hits any of the buttons
{
...
}